Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signup and login features #170

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,657 changes: 3,657 additions & 0 deletions dist/bundle.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions generators/js-framework/modules/angularjs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ angular.module('MyApp', ['ngRoute'<%= satellizer %>])
.when('/login', {
templateUrl: 'partials/login.html',
controller: 'LoginCtrl',
controllerAs: 'login',
resolve: { skipIfAuthenticated: skipIfAuthenticated }
})
.when('/signup', {
templateUrl: 'partials/signup.html',
controller: 'SignupCtrl',
controllerAs: 'signUp',
resolve: { skipIfAuthenticated: skipIfAuthenticated }
})
.when('/account', {
templateUrl: 'partials/profile.html',
controller: 'ProfileCtrl',
controllerAs: 'profile',
resolve: { loginRequired: loginRequired }
})
.when('/forgot', {
Expand Down
64 changes: 32 additions & 32 deletions generators/js-framework/modules/angularjs/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@
angular.module('MyApp')
.controller('LoginCtrl', LoginCtrl);

LoginCtrl.$inject = ['$scope', '$rootScope', '$location', '$window', '$auth'];
LoginCtrl.$inject = ['$rootScope', '$location', '$window', '$auth'];

function LoginCtrl($scope, $rootScope, $location, $window, $auth) {
function LoginCtrl($rootScope, $location, $window, $auth) {
var ctrl = this;
ctrl.login = login;
ctrl.authenticate = authenticate;

function login() {
$auth.login($scope.user)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/account');
})
.catch(function(response) {
$scope.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
function login(){
$auth.login(ctrl.user)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/account');
})
.catch(function(response) {
ctrl.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}

function authenticate(provider) {
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
$scope.messages = {
error: [{ msg: response.error }]
};
} else if (response.data) {
$scope.messages = {
error: [response.data]
};
}
});
function authenticate(provider){
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
ctrl.messages = {
error: [{ msg: response.error }]
};
} else if (response.data) {
ctrl.messages = {
error: [response.data]
};
}
});
}
}
})();
32 changes: 16 additions & 16 deletions generators/js-framework/modules/angularjs/controllers/profile.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
(function() {
angular.module('MyApp')
.controller('ContactCtrl', ContactCtrl);
.controller('ProfileCtrl', ProfileCtrl);

ContactCtrl.$inject = ['$scope', '$rootScope', '$location', '$window', '$auth', 'Account'];
ProfileCtrl.$inject = ['$rootScope', '$location', '$window', '$auth', 'Account'];

function ContactCtrl($scope, $rootScope, $location, $window, $auth, Account) {
function ProfileCtrl($rootScope, $location, $window, $auth, Account) {
var ctrl = this;
ctrl.updateProfile = updateProfile;
ctrl.changePassword = changePassword;
ctrl.link = link;
ctrl.unlink = unlink;
ctrl.deleteAccount = deleteAccount;
ctrl.unlink = unlink;
$scope.profile = $rootScope.currentUser;
ctrl.profile = $rootScope.currentUser;

function updateProfile() {
Account.updateProfile($scope.profile)
Account.updateProfile(ctrl.profile)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$scope.messages = {
ctrl.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
ctrl.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}

function changePassword() {
Account.changePassword($scope.profile)
Account.changePassword(ctrl.profile)
.then(function(response) {
$scope.messages = {
ctrl.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
ctrl.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
Expand All @@ -47,13 +47,13 @@ function ContactCtrl($scope, $rootScope, $location, $window, $auth, Account) {
function link(provider) {
$auth.link(provider)
.then(function(response) {
$scope.messages = {
ctrl.messages = {
success: [response.data]
};
})
.catch(function(response) {
$window.scrollTo(0, 0);
$scope.messages = {
ctrl.messages = {
error: [response.data]
};
});
Expand All @@ -62,27 +62,27 @@ function ContactCtrl($scope, $rootScope, $location, $window, $auth, Account) {
function unlink(provider) {
$auth.unlink(provider)
.then(function() {
$scope.messages = {
ctrl.messages = {
success: [response.data]
};
})
.catch(function(response) {
$scope.messages = {
ctrl.messages = {
error: [response.data]
};
});
}

function deleteAccount() {
$scope.deleteAccount = function() {
ctrl.deleteAccount = function() {
Account.deleteAccount()
.then(function() {
$auth.logout();
delete $window.localStorage.user;
$location.path('/');
})
.catch(function(response) {
$scope.messages = {
ctrl.messages = {
error: [response.data]
};
});
Expand Down
47 changes: 24 additions & 23 deletions generators/js-framework/modules/angularjs/controllers/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@
angular.module('MyApp')
.controller('SignupCtrl', SignupCtrl);

SignupCtrl.$inject = ['$scope', '$rootScope', '$location', '$window', '$auth'];
SignupCtrl.$inject = ['$rootScope', '$location', '$window', '$auth'];

function SignupCtrl($rootScope, $location, $window, $auth) {

function SignupCtrl($scope, $rootScope, $location, $window, $auth) {
var ctrl = this;
ctrl.signup = signup;
ctrl.authenticate = authenticate;

function signup() {
$auth.signup($scope.user)
function signup(){
$auth.signup(ctrl.user)
.then(function(response) {
$auth.setToken(response);
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
$scope.messages = {
ctrl.messages = {
error: Array.isArray(response.data) ? response.data : [response.data]
};
});
}

function authenticate(provider) {
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
$scope.messages = {
error: [{ msg: response.error }]
};
} else if (response.data) {
$scope.messages = {
error: [response.data]
};
}
});
function authenticate(provider){
$auth.authenticate(provider)
.then(function(response) {
$rootScope.currentUser = response.data.user;
$window.localStorage.user = JSON.stringify(response.data.user);
$location.path('/');
})
.catch(function(response) {
if (response.error) {
ctrl.messages = {
error: [{ msg: response.error }]
};
} else if (response.data) {
ctrl.messages = {
error: [response.data]
};
}
});
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul ng-if="isAuthenticated()" class="nav navbar-nav navbar-right">
<ul ng-if="header.isAuthenticated()" class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="navbar-avatar dropdown-toggle">
<img ng-src="{{currentUser.picture || currentUser.gravatar}}"> {{currentUser.name || currentUser.email || currentUser.id}} <i class="caret"></i>
Expand All @@ -10,7 +10,7 @@
</ul>
</li>
</ul>
<ul ng-if="!isAuthenticated()" class="nav navbar-nav navbar-right">
<li ng-class="{ active: isActive('/login')}"><a href="/login">Log in</a></li>
<li ng-class="{ active: isActive('/signup')}"><a href="/signup">Sign up</a></li>
<ul ng-if="!header.isAuthenticated()" class="nav navbar-nav navbar-right">
<li ng-class="{ active: header.isActive('/login')}"><a href="/login">Log in</a></li>
<li ng-class="{ active: header.isActive('/signup')}"><a href="/signup">Sign up</a></li>
</ul>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div ng-if="isAuthenticated()" class="top-bar-right">
<div ng-if="header.isAuthenticated()" class="top-bar-right">
<ul class="vertical medium-horizontal menu">
<li><a href="/account" ng-class="{ active: isActive('/account')}">My Account</a></li>
<li><a href="#" ng-click="logout()">Logout</a></li>
</ul>
</div>
<div ng-if="!isAuthenticated()" class="top-bar-right">
<div ng-if="!header.isAuthenticated()" class="top-bar-right">
<ul class="vertical medium-horizontal menu">
<li><a href="/login" ng-class="{ active: isActive('/login')}">Log in</a></li>
<li><a href="/signup" ng-class="{ active: isActive('/signup')}">Sign up</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ul ng-if="isAuthenticated()" class="list-inline">
<ul ng-if="header.isAuthenticated()" class="list-inline">
<li><a href="/account" ng-class="{ active: isActive('/account')}">My Account</a></li>
<li><a href="#" ng-click="logout()">Logout</a></li>
</ul>
<ul ng-if="!isAuthenticated()" class="list-inline">
<ul ng-if="!header.isAuthenticated()" class="list-inline">
<li><a href="/login" ng-class="{ active: isActive('/login')}">Log in</a></li>
<li><a href="/signup" ng-class="{ active: isActive('/signup')}">Sign up</a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav ng-controller="HeaderCtrl" class="navbar navbar-default navbar-static-top">
<nav ng-controller="HeaderCtrl as header" class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target="#navbar" class="navbar-toggle collapsed">
Expand All @@ -11,8 +11,8 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li ng-class="{ active: isActive('/')}"><a href="/">Home</a></li>
<li ng-class="{ active: isActive('/contact')}"><a href="/contact">Contact</a></li>
<li ng-class="{ active: header.isActive('/')}"><a href="/">Home</a></li>
<li ng-class="{ active: header.isActive('/contact')}"><a href="/contact">Contact</a></li>
</ul>
//= HEADER_AUTH
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="HeaderCtrl" class="top-bar">
<div ng-controller="HeaderCtrl as header" class="top-bar">
<div class="top-bar-title">
<span data-responsive-toggle="responsive-menu" data-hide-for="medium">
<span class="menu-icon light" data-toggle></span>
Expand All @@ -8,8 +8,8 @@
<div id="responsive-menu">
<div class="top-bar-left">
<ul class="vertical medium-horizontal menu">
<li><a href="/" ng-class="{ active: isActive('/')}">Home</a></li>
<li><a href="/contact" ng-class="{ active: isActive('/contact')}">Contact</a></li>
<li><a href="/" ng-class="{ active: header.isActive('/')}">Home</a></li>
<li><a href="/contact" ng-class="{ active: header.isActive('/contact')}">Contact</a></li>
</ul>
</div>
//= HEADER_AUTH
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="HeaderCtrl" class="container">
<div ng-controller="HeaderCtrl as header" class="container">
<ul class="list-inline">
<li><a href="/">Home</a></li>
<li><a href="/contact">Contact</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<div class="container login-container">
<div class="panel">
<div class="panel-body">
<div ng-if="messages.error" role="alert" class="alert alert-danger">
<div ng-repeat="error in messages.error">{{error.msg}}</div>
<div ng-if="login.messages.error" role="alert" class="alert alert-danger">
<div ng-repeat="error in login.messages.error">{{error.msg}}</div>
</div>
<form ng-submit="login()">
<form ng-submit="login.login()">
<legend>Log In</legend>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" placeholder="Email" class="form-control" ng-model="user.email" autofocus>
<input type="email" name="email" id="email" placeholder="Email" class="form-control" ng-model="login.user.email" autofocus>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" placeholder="Password" class="form-control" ng-model="user.password">
<input type="password" name="password" id="password" placeholder="Password" class="form-control" ng-model="login.user.password">
</div>
<div class="form-group"><a href="/forgot"><strong>Forgot your password?</strong></a></div>
<button type="submit" class="btn btn-success">Log in</button>
Expand Down
Loading