Skip to content

Commit

Permalink
Logging in and Registration, independent from accounts-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
simonv3 committed Sep 18, 2015
1 parent a880887 commit 0bd6824
Show file tree
Hide file tree
Showing 34 changed files with 19,218 additions and 164 deletions.
1 change: 0 additions & 1 deletion .meteor/packages
Expand Up @@ -8,7 +8,6 @@ meteor-platform
urigo:angular
angularui:angular-ui-router
accounts-password
accounts-ui
less
tmeasday:publish-counts
oshai:angular-marked
Expand Down
2 changes: 0 additions & 2 deletions .meteor/versions
@@ -1,7 +1,5 @@
accounts-base@1.2.0
accounts-password@1.1.1
accounts-ui@1.1.5
accounts-ui-unstyled@1.1.7
angular:angular@1.4.4
angularui:angular-ui-router@0.2.15
autoupdate@1.2.1
Expand Down
4 changes: 4 additions & 0 deletions client/config/accounts.js
@@ -0,0 +1,4 @@
Accounts.onEmailVerificationLink(function(token, done) {
Accounts.verifyEmail(token);
done();
});
47 changes: 47 additions & 0 deletions client/index.html
@@ -0,0 +1,47 @@
<head>
<base href="/">
<title>Quick Survey</title>
</head>

<body ng-app="quick-survey">
<div class="page-wrap">
<div class="nav" ng-controller="NavBarCtrl">
<div class="admin" ng-if="is_admin">
<a href="/">survey</a>
<a href="/admin">admin</a>
</div>
<div class="registration"
ng-if="state.current.name !== 'setup'">
<a class="button"
ng-href="/login"
ng-hide="$root.currentUser">Log in</a>
<a class="button"
ng-href="/register"
ng-hide="$root.currentUser">Register</a>
<div class="username"
ng-show="$root.currentUser">
Hello <span ng-bind="$root.currentUser | displayName"></span>
</div>
<a class="button"
ng-href="/logout"
ng-show="$root.currentUser">Log out</a>
</div>
</div>
<div ui-view
class="container small-row"
ng-class="{ admin: $state.includes('admin') }">
</div>
</div>
<div ng-show="loading">
<span></span>
<span></span>
<span></span>
</div>
<footer class="site-footer">
<div class="wide-row footer-wrapper">
<img src="/images/squirrel-small.png" alt="Quick Survey Squirrel Logo"/>
<p>Powered by Quick-Survey, a self-hosted, easy-to-install survey tool that you control and own. Get started on <a href="https://github.com/simonv3/quick-survey"><i class="icon-github"></i> GitHub</a>.
</p>
</div>
</footer>
</body>
13 changes: 13 additions & 0 deletions client/js/filters/displayName.js
@@ -0,0 +1,13 @@
angular.module('quick-survey').filter('displayName', function () {
return function (user) {
if (!user)
return;
if (user.profile && user.profile.name)
return user.profile.name;
else if (user.emails)
return user.emails[0].address;
else
return user;
}
});

45 changes: 42 additions & 3 deletions client/js/routes.ng.js
Expand Up @@ -15,18 +15,22 @@ angular.module('quick-survey').run(function($rootScope, $state) {
});

$rootScope.$watch('currentUser', function() {
console.log('currentUser', $rootScope.currentUser);
if (!$rootScope.loggingIn && $rootScope.currentUser === null) {
$state.go('active-survey');
}
});

});

angular.module("quick-survey").config(['$urlRouterProvider', '$stateProvider', '$locationProvider',
function ($urlRouterProvider, $stateProvider, $locationProvider) {
angular.module("quick-survey").config(
function ($urlRouterProvider, $stateProvider, $locationProvider,
$urlMatcherFactoryProvider) {

$locationProvider.html5Mode(true);

$urlMatcherFactoryProvider.strictMode(false);

$stateProvider
.state('active-survey', {
url: '/',
Expand Down Expand Up @@ -82,7 +86,42 @@ angular.module("quick-survey").config(['$urlRouterProvider', '$stateProvider', '
});
}]
}
})

.state('login', {
url: '/login',
templateUrl: 'client/js/users/views/login.ng.html',
controller: 'LoginCtrl',
controllerAs: 'lc'
})
.state('register',{
url: '/register',
templateUrl: 'client/js/users/views/register.ng.html',
controller: 'RegisterCtrl',
controllerAs: 'rc'
})
.state('register-success', {
url: '/register/success',
templateUrl: 'client/js/users/views/register-success.ng.html',
})
.state('reset-password', {
url: '/reset-password',
templateUrl: 'client/js/users/views/reset-password.ng.html',
controller: 'ResetPasswordCtrl',
controllerAs: 'rpc'
})
.state('logout', {
url: '/logout',
resolve: {
"logout": ['$meteor', '$state', function($meteor, $state) {
return $meteor.logout().then(function(){
$state.go('active-survey');
}, function(err){
console.log('logout error - ', err);
});
}]
}
});

$urlRouterProvider.otherwise("/");
}]);
});
28 changes: 28 additions & 0 deletions client/js/users/controllers/loginCtrl.ng.js
@@ -0,0 +1,28 @@
angular.module("quick-survey").controller("LoginCtrl",
function ($meteor, $state) {
var vm = this;

vm.credentials = {
email: '',
password: ''
};

vm.error = '';

vm.sendEmailVerification = function() {
Meteor.call('resendVerificationEmail', vm.credentials.email);
};

vm.login = function () {
$meteor.loginWithPassword(vm.credentials.email, vm.credentials.password).then(
function () {
$state.go('active-survey');
},
function (err) {
vm.error = err;
}
);
};
}
);

26 changes: 26 additions & 0 deletions client/js/users/controllers/registerCtrl.ng.js
@@ -0,0 +1,26 @@
angular.module("quick-survey").controller("RegisterCtrl",
function ($meteor, $state) {
var vm = this;

vm.credentials = {
email: '',
password: ''
};

vm.error = '';

vm.register = function () {
$meteor.createUser(vm.credentials).then(
function (response) {
console.log(vm.currentUser);
vm.success = true;
},
function (err) {
if (err.error === 'account-created') $state.go('register-success')
vm.error = err;
}
);
};
}
);

23 changes: 23 additions & 0 deletions client/js/users/controllers/resetPasswordCtrl.ng.js
@@ -0,0 +1,23 @@
angular.module("quick-survey").controller("ResetPasswordCtrl",
function ($meteor, $state) {
var vm = this;

vm.credentials = {
email: ''
};

vm.error = '';

vm.reset = function () {
$meteor.forgotPassword(vm.credentials.email).then(
function () {
$state.go('active-survey');
},
function (err) {
vm.error = 'Error sending forgot password email - ' + err;
}
);
};
}
);

31 changes: 31 additions & 0 deletions client/js/users/views/login.ng.html
@@ -0,0 +1,31 @@
<div class="frontend">
<h1>Log in</h1>
<form class="registration-form" name="loginForm">
<!-- <div>
<h2>Login with:</h2>
<button>Twitter</button>
<button>Facebook</button>
</div> -->
<div ng-show="lc.error" class="md-warn">
<small>
{{ lc.error.reason }}
<a ng-if="lc.error.error === 'verify-account'" ng-click="lc.sendEmailVerification()">Re-send.
</a>
</small>
</div>
<input type="text"
ng-model="lc.credentials.email"
placeholder="email"
aria-label="email"/>
<input type="password"
ng-model="lc.credentials.password"
placeholder="password"
aria-label="password"/>
<button ng-disabled="!loginForm.$valid"
ng-click="lc.login()">Submit</button>
</form>
<div>
<a href="/reset-password">Forgot password?</a>
<a href="/register">Create an account</a>
</div>
</div>
3 changes: 3 additions & 0 deletions client/js/users/views/register-success.ng.html
@@ -0,0 +1,3 @@
<div class="message empty-state success">
Great, check your e-mail for a verification e-mail!
</div>
34 changes: 34 additions & 0 deletions client/js/users/views/register.ng.html
@@ -0,0 +1,34 @@
<div class="frontend">
<h1>Register</h1>
<form class="registration-form"
name="registerForm">
<!-- <div>
<h2>Register with:</h2>
<button>Twitter</button>
<button>Facebook</button>
</div> -->
<div ng-show="rc.error" class="message warning">
<small>{{ rc.error.reason }}</small>
</div>

<input type="email"
ng-model="rc.credentials.email"
placeholder="email"
aria-label="email"
required/>
<input type="password"
ng-model="rc.credentials.password"
placeholder="password"
aria-label="password"
required/>
<button ng-disabled="!registerForm.$valid"
ng-click="rc.register()">Register</button>
</form>
<div ng-show="rc.success" class="message success">
<small>Great, check your email for a verification e-mail!</small>
</div>
<div>
<a href="/reset-password">Forgot password?</a>
<a href="/login">Log in</a>
</div>
</div>
24 changes: 24 additions & 0 deletions client/js/users/views/reset-password.ng.html
@@ -0,0 +1,24 @@
<div class="frontend">
<h1>Register</h1>
<form class="login-form" name="resetPasswordForm">
<div>
<h2>Register with:</h2>
<button>Twitter</button>
<button>Facebook</button>
</div>
<div ng-show="rc.error" class="md-warn">
<small>{{ rc.error }}</small>
</div>
<input type="text"
ng-model="rpc.credentials.email"
placeholder="email"
aria-label="email"
required/>
<button ng-disabled="!resetPasswordForm.$valid"
ng-click="rpc.register()">Submit</button>
</form>
<div>
<a href="/resetpw">Forgot password?</a>
<a href="/register">Create an account</a>
</div>
</div>
43 changes: 43 additions & 0 deletions client/styles/animations.import.less
@@ -0,0 +1,43 @@
@-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
-moz-transform: scale(2);
}
to {
-moz-transform: scale(1);
-moz-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
from {
transform: scale(2);
transform: rotate(0deg);
}
to {
transform: scale(1);
transform: rotate(360deg);
}
}

.animation(@name, @duration, @iterationCount, @timingFunction) {
-webkit-animation-name: @name;
-webkit-animation-duration: @duration;
-webkit-animation-iteration-count: @iterationCount;
-webkit-animation-timing-function: @timingFunction;
-moz-animation-name: @name;
-moz-animation-duration: @duration;
-moz-animation-iteration-count: @iterationCount;
-moz-animation-timing-function: @timingFunction;
-ms-animation-name: @name;
-ms-animation-duration: @duration;
-ms-animation-iteration-count: @iterationCount;
-ms-animation-timing-function: @timingFunction;
}

0 comments on commit 0bd6824

Please sign in to comment.