Skip to content

Commit

Permalink
wip on authorizations
Browse files Browse the repository at this point in the history
* add and configure bower
* add basic logic for auth

@dodo121
  • Loading branch information
dodo121 committed Sep 17, 2016
1 parent 8ad93dd commit 24cf924
Show file tree
Hide file tree
Showing 36 changed files with 35,333 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular.module('Organizer').controller('UserSessionsCtrl', ['$scope', 'Navbar', ($scope, Navbar) ->
Navbar.switchTo('#sign-in-link')
])
7 changes: 6 additions & 1 deletion app/assets/javascripts/main.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#= require_tree ./factories
#= require_tree ./controllers/home
#= require_tree ./controllers/notes
#= require_tree ./controllers/sessions
#= require_tree ./directives
#= require angular-cookie/angular-cookie
#= require ng-token-auth/src/ng-token-auth

Organizer = angular.module('Organizer', ['ngRoute', 'ngResource', 'ngAnimate', 'templates'])
Organizer = angular.module('Organizer', ['ngRoute', 'ngResource', 'ngAnimate', 'templates', 'ng-token-auth'])

Organizer.config(['$routeProvider', ($routeProvider) ->
$routeProvider.when('/notes', { templateUrl: 'notesIndex.html', controller: 'NotesCtrl' } )

$routeProvider.when('/sign_in', { templateUrl: 'new.html', controller: 'UserSessionsCtrl'})

$routeProvider.otherwise({ templateUrl: 'homeIndex.html', controller: 'IndexCtrl' } )
])
29 changes: 29 additions & 0 deletions app/assets/javascripts/templates/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div id="template-with-background">
<div id="content">
<form ng-submit="submitLogin(loginForm)" role="form" ng-init="loginForm = {}">
<div class="form-group">
<label for="email">Email
<input type="email"
name="email"
id="email"
ng-model="loginForm.email"
required="required"
class="form-control">
</label>
</div>

<div class="form-group">
<label for="password">Password
<input type="password"
name="password"
id="password"
ng-model="loginForm.password"
required="required"
class="form-control">
</label>
</div>

<button type="submit" class="btn btn-primary btn-lg">Sign in</button>
</form>
</div>
</div>
11 changes: 10 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
@import 'main';
@import 'navbar';
@import "notes";
@import 'buttons';
@import 'buttons';

#template-with-background {
margin: 50px 0;
background: #EFEFEF;

#content {
padding: 25px;
}
}
6 changes: 5 additions & 1 deletion app/views/layouts/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
Home
%span.sr-only (current)
%li.nav-link#notes-link
%a{:href => "#notes"} Notes
%a{:href => "#notes"} Notes
%li.nav-link#sign-in-link
%a{'ng-show'=>'!user.id', 'href'=>'#sign_in'} Sign in
%li.nav-link
%a{'ng-show'=>'user.id', 'ng-click'=>'signOut()'} Sign out
23 changes: 23 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "organizer",
"version": "0.0.0",
"homepage": "https://github.com/dodo121/organizer",
"authors": [
"Dominik Szromik <[email protected]>"
],
"description": "bower files for organizer app",
"moduleType": [
"node"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"ng-token-auth": "^0.0.29"
}
}
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[4.2]
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Required
Expand Down
31 changes: 30 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150929173908) do
ActiveRecord::Schema.define(version: 20160912162555) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -22,4 +22,33 @@
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade do |t|
t.string "provider", default: "email", null: false
t.string "uid", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "name"
t.string "nickname"
t.string "image"
t.string "email"
t.json "tokens"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "users", ["email"], name: "index_users_on_email", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree

end
3 changes: 3 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
10.times do
Note.create(content: Faker::Lorem.sentences(rand(5)).join(' '))
end

User.create(email: '[email protected]', password: 'yourpassword', password_confirmation: 'yourpassword',
confirmed_at: Time.zone.now)
3 changes: 3 additions & 0 deletions vendor/assets/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
40 changes: 40 additions & 0 deletions vendor/assets/bower_components/angular-cookie/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "angular-cookie",
"main": "angular-cookie.js",
"version": "4.1.0",
"homepage": "https://github.com/ivpusic/angular-cookie",
"authors": [
"ivpusic <[email protected]>"
],
"description": "angular module for accessing browser cookies",
"keywords": [
"cookie",
"angular"
],
"license": "MIT",
"location": "[email protected]:ivpusic/angular-cookie.git",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"example",
"karma.conf.js",
"LICENSE",
"README.md",
"Gruntfile.js"
],
"dependencies": {
"angular": "*"
},
"_release": "4.1.0",
"_resolution": {
"type": "version",
"tag": "v4.1.0",
"commit": "514a9df3ead0d60149c62231169adfc903e34489"
},
"_source": "https://github.com/ivpusic/angular-cookie.git",
"_target": "~4.1.0",
"_originalSource": "angular-cookie"
}
125 changes: 125 additions & 0 deletions vendor/assets/bower_components/angular-cookie/angular-cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2013 Ivan Pusic
* Contributors:
* Matjaz Lipus
*/
angular.module('ivpusic.cookie', ['ipCookie']);
angular.module('ipCookie', ['ng']).
factory('ipCookie', ['$document',
function ($document) {
'use strict';

function tryDecodeURIComponent(value) {
try {
return decodeURIComponent(value);
} catch(e) {
// Ignore any invalid uri component
}
}

return (function () {
function cookieFun(key, value, options) {

var cookies,
list,
i,
cookie,
pos,
name,
hasCookies,
all,
expiresFor;

options = options || {};
var dec = options.decode || tryDecodeURIComponent;
var enc = options.encode || encodeURIComponent;

if (value !== undefined) {
// we are setting value
value = typeof value === 'object' ? JSON.stringify(value) : String(value);

if (typeof options.expires === 'number') {
expiresFor = options.expires;
options.expires = new Date();
// Trying to delete a cookie; set a date far in the past
if (expiresFor === -1) {
options.expires = new Date('Thu, 01 Jan 1970 00:00:00 GMT');
// A new
} else if (options.expirationUnit !== undefined) {
if (options.expirationUnit === 'hours') {
options.expires.setHours(options.expires.getHours() + expiresFor);
} else if (options.expirationUnit === 'minutes') {
options.expires.setMinutes(options.expires.getMinutes() + expiresFor);
} else if (options.expirationUnit === 'seconds') {
options.expires.setSeconds(options.expires.getSeconds() + expiresFor);
} else if (options.expirationUnit === 'milliseconds') {
options.expires.setMilliseconds(options.expires.getMilliseconds() + expiresFor);
} else {
options.expires.setDate(options.expires.getDate() + expiresFor);
}
} else {
options.expires.setDate(options.expires.getDate() + expiresFor);
}
}
return ($document[0].cookie = [
enc(key),
'=',
enc(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '',
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

list = [];
all = $document[0].cookie;
if (all) {
list = all.split('; ');
}

cookies = {};
hasCookies = false;

for (i = 0; i < list.length; ++i) {
if (list[i]) {
cookie = list[i];
pos = cookie.indexOf('=');
name = cookie.substring(0, pos);
value = dec(cookie.substring(pos + 1));
if(angular.isUndefined(value))
continue;

if (key === undefined || key === name) {
try {
cookies[name] = JSON.parse(value);
} catch (e) {
cookies[name] = value;
}
if (key === name) {
return cookies[name];
}
hasCookies = true;
}
}
}
if (hasCookies && key === undefined) {
return cookies;
}
}
cookieFun.remove = function (key, options) {
var hasCookie = cookieFun(key) !== undefined;

if (hasCookie) {
if (!options) {
options = {};
}
options.expires = -1;
cookieFun(key, '', options);
}
return hasCookie;
};
return cookieFun;
}());
}
]);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/assets/bower_components/angular-cookie/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "angular-cookie",
"main": "angular-cookie.js",
"version": "4.1.0",
"homepage": "https://github.com/ivpusic/angular-cookie",
"authors": [
"ivpusic <[email protected]>"
],
"description": "angular module for accessing browser cookies",
"keywords": [
"cookie",
"angular"
],
"license": "MIT",
"location": "[email protected]:ivpusic/angular-cookie.git",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"example",
"karma.conf.js",
"LICENSE",
"README.md",
"Gruntfile.js"
],
"dependencies": {
"angular": "*"
}
}
2 changes: 2 additions & 0 deletions vendor/assets/bower_components/angular-cookie/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('./angular-cookie');
module.exports = 'ipCookie';
Loading

0 comments on commit 24cf924

Please sign in to comment.