got user email verification working
This commit is contained in:
parent
7abf9e92a9
commit
e552e03f81
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -22,6 +22,8 @@ config/sslcerts/*.pem
|
||||||
access.log
|
access.log
|
||||||
#public/dist/
|
#public/dist/
|
||||||
uploads/
|
uploads/
|
||||||
|
# API keys file
|
||||||
|
api_keys.js
|
||||||
|
|
||||||
# Sublime editor
|
# Sublime editor
|
||||||
# ==============
|
# ==============
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
angular.module('users').controller('VerifyController', ['$scope', '$location', '$state', '$rootScope', 'User', 'Auth',
|
|
||||||
function($scope, $location, $state, $rootScope, User, Auth) {
|
|
||||||
|
|
||||||
$scope = $rootScope;
|
|
||||||
$scope.credentials = {};
|
|
||||||
$scope.error = null;
|
|
||||||
$scope.success = null;
|
|
||||||
|
|
||||||
// If user is signed in then redirect back home
|
|
||||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
|
||||||
|
|
||||||
$scope.validateVerifyToken = function(){
|
|
||||||
$scope.success = $scope.error = null;
|
|
||||||
User.validateVerifyToken($stateParams.token).then(
|
|
||||||
function(response){
|
|
||||||
// If successful show success message and clear form
|
|
||||||
$scope.success = response.message;
|
|
||||||
$scope.passwordDetails = null;
|
|
||||||
},
|
|
||||||
function(error){
|
|
||||||
$scope.error = error.message || error;
|
|
||||||
$scope.passwordDetails = null;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Submit forgotten password account id
|
|
||||||
$scope.resendVerifyEmail = function() {
|
|
||||||
User.resendVerifyEmail($scope.email).then(
|
|
||||||
function(response){
|
|
||||||
$scope.success = response.message;
|
|
||||||
$scope.credentials = null;
|
|
||||||
},
|
|
||||||
function(error){
|
|
||||||
$scope.error = error;
|
|
||||||
$scope.credentials = null;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
]);
|
|
|
@ -54,7 +54,7 @@
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body ng-cloak ng-app="medform">
|
<body ng-cloak>
|
||||||
<header data-ng-include="'/modules/core/views/header.client.view.html'"></header>
|
<header data-ng-include="'/modules/core/views/header.client.view.html'"></header>
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<!-- <section class="container"> -->
|
<!-- <section class="container"> -->
|
||||||
|
|
|
@ -13,7 +13,8 @@ var _ = require('lodash'),
|
||||||
*/
|
*/
|
||||||
module.exports = _.extend(
|
module.exports = _.extend(
|
||||||
require('./env/all'),
|
require('./env/all'),
|
||||||
require('./env/' + process.env.NODE_ENV) || {}
|
require('./env/' + process.env.NODE_ENV) || {},
|
||||||
|
require('./env/api_keys.js') || {}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
8
config/env/development.js
vendored
8
config/env/development.js
vendored
|
@ -46,12 +46,12 @@ module.exports = {
|
||||||
callbackURL: '/auth/github/callback'
|
callbackURL: '/auth/github/callback'
|
||||||
},
|
},
|
||||||
mailer: {
|
mailer: {
|
||||||
from: process.env.MAILER_FROM || 'hi@example.com',
|
from: process.env.MAILER_FROM || '',
|
||||||
options: {
|
options: {
|
||||||
service: process.env.MAILER_SERVICE_PROVIDER || 'Mandrill',
|
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.MAILER_EMAIL_ID || 'hackouver@gmail.com',
|
user: process.env.MAILER_EMAIL_ID || '',
|
||||||
pass: process.env.MAILER_PASSWORD || 'ehOLuSXCBFxLjipRalBxVg'
|
pass: process.env.MAILER_PASSWORD || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
config/env/production.js
vendored
8
config/env/production.js
vendored
|
@ -61,12 +61,12 @@ module.exports = {
|
||||||
callbackURL: '/auth/github/callback'
|
callbackURL: '/auth/github/callback'
|
||||||
},
|
},
|
||||||
mailer: {
|
mailer: {
|
||||||
from: process.env.MAILER_FROM || 'noreply@forms.polydaic.com',
|
from: process.env.MAILER_FROM || '',
|
||||||
options: {
|
options: {
|
||||||
service: process.env.MAILER_SERVICE_PROVIDER || 'Mandrill',
|
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.MAILER_EMAIL_ID || 'hackouver@gmail.com',
|
user: process.env.MAILER_EMAIL_ID || '',
|
||||||
pass: process.env.MAILER_PASSWORD || 'ehOLuSXCBFxLjipRalBxVg'
|
pass: process.env.MAILER_PASSWORD || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
config/env/secure.js
vendored
8
config/env/secure.js
vendored
|
@ -62,12 +62,12 @@ module.exports = {
|
||||||
callbackURL: 'https://localhost:443/auth/github/callback'
|
callbackURL: 'https://localhost:443/auth/github/callback'
|
||||||
},
|
},
|
||||||
mailer: {
|
mailer: {
|
||||||
from: process.env.MAILER_FROM || 'noreply@forms.polydaic.com',
|
from: process.env.MAILER_FROM || '',
|
||||||
options: {
|
options: {
|
||||||
service: process.env.MAILER_SERVICE_PROVIDER || 'Mandrill',
|
service: process.env.MAILER_SERVICE_PROVIDER || '',
|
||||||
auth: {
|
auth: {
|
||||||
user: process.env.MAILER_EMAIL_ID || 'hackouver@gmail.com',
|
user: process.env.MAILER_EMAIL_ID || '',
|
||||||
pass: process.env.MAILER_PASSWORD || 'ehOLuSXCBFxLjipRalBxVg'
|
pass: process.env.MAILER_PASSWORD || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
fig.yml
12
fig.yml
|
@ -1,12 +0,0 @@
|
||||||
web:
|
|
||||||
build: .
|
|
||||||
links:
|
|
||||||
- db
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
environment:
|
|
||||||
NODE_ENV: development
|
|
||||||
db:
|
|
||||||
image: mongo
|
|
||||||
ports:
|
|
||||||
- "27017:27017"
|
|
|
@ -131,10 +131,13 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
test: {
|
test: {
|
||||||
NODE_ENV: 'test'
|
NODE_ENV: 'test',
|
||||||
},
|
},
|
||||||
secure: {
|
secure: {
|
||||||
NODE_ENV: 'secure'
|
NODE_ENV: 'secure'
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
src: 'ENV.json'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mochaTest: {
|
mochaTest: {
|
||||||
|
|
2
public/dist/application.min.css
vendored
2
public/dist/application.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,7 @@ angular.module('users').config(['$httpProvider',
|
||||||
$httpProvider.interceptors.push(function($q, $location) {
|
$httpProvider.interceptors.push(function($q, $location) {
|
||||||
return {
|
return {
|
||||||
responseError: function(response) {
|
responseError: function(response) {
|
||||||
if( $location.path() !== '/users/me' && $location.path() !== '/' && $location.path() !== '/signup' && response.config){
|
if( $location.path() !== '/verify' && $location.path() !== '/users/me' && $location.path() !== '/' && $location.path() !== '/signup' && response.config){
|
||||||
|
|
||||||
console.log('intercepted rejection of ', response.config.url, response.status);
|
console.log('intercepted rejection of ', response.config.url, response.status);
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
|
|
|
@ -49,20 +49,5 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Submit forgotten password account id
|
|
||||||
$scope.resendVerifyEmail = function() {
|
|
||||||
User.resendVerifyEmail($scope.email).then(
|
|
||||||
function(response){
|
|
||||||
$scope.success = response.message;
|
|
||||||
$scope.credentials = null;
|
|
||||||
},
|
|
||||||
function(error){
|
|
||||||
$scope.error = error;
|
|
||||||
$scope.credentials = null;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
46
public/modules/users/controllers/verify.client.controller.js
Normal file
46
public/modules/users/controllers/verify.client.controller.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('users').controller('VerifyController', ['$scope', '$state', '$rootScope', 'User', 'Auth', '$stateParams',
|
||||||
|
function($scope, $state, $rootScope, User, Auth, $stateParams) {
|
||||||
|
if($rootScope.authetication.isAuthenticated){
|
||||||
|
$state.go('home');
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.isReset = false;
|
||||||
|
|
||||||
|
// Submit forgotten password account id
|
||||||
|
$scope.resendVerifyEmail = function() {
|
||||||
|
User.resendVerifyEmail($scope.email).then(
|
||||||
|
function(response){
|
||||||
|
$scope.success = response.message;
|
||||||
|
$scope.credentials = null;
|
||||||
|
},
|
||||||
|
function(error){
|
||||||
|
$scope.error = error;
|
||||||
|
$scope.credentials = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
//Validate Verification Token
|
||||||
|
$scope.validateVerifyToken = function() {
|
||||||
|
if($stateParams.token){
|
||||||
|
console.log($stateParams.token);
|
||||||
|
User.validateVerifyToken($stateParams.token).then(
|
||||||
|
function(response){
|
||||||
|
console.log('Success: '+response.message);
|
||||||
|
$scope.success = response.message;
|
||||||
|
$scope.isReset = true;
|
||||||
|
$scope.credentials = null;
|
||||||
|
},
|
||||||
|
function(error){
|
||||||
|
console.log('Error: '+error.message);
|
||||||
|
$scope.isReset = false;
|
||||||
|
$scope.error = error;
|
||||||
|
$scope.credentials = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
|
@ -56,9 +56,8 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '
|
||||||
|
|
||||||
resendVerifyEmail: function(email) {
|
resendVerifyEmail: function(email) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
$http.post('/auth/verify/'+token, email).success(function(response) {
|
$http.post('/auth/verify/', {email: email}).success(function(response) {
|
||||||
|
deferred.resolve(response);
|
||||||
deferred.resolve();
|
|
||||||
}).error(function(error) {
|
}).error(function(error) {
|
||||||
deferred.reject(error.message || error);
|
deferred.reject(error.message || error);
|
||||||
});
|
});
|
||||||
|
@ -66,6 +65,17 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validateVerifyToken: function(token) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
$http.get('/auth/verify/'+token).success(function(response) {
|
||||||
|
deferred.resolve(response);
|
||||||
|
}).error(function(error) {
|
||||||
|
deferred.reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
|
||||||
resetPassword: function(passwordDetails, token) {
|
resetPassword: function(passwordDetails, token) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
$http.get('/auth/password/'+token, passwordDetails).success(function(response) {
|
$http.get('/auth/password/'+token, passwordDetails).success(function(response) {
|
||||||
|
|
|
@ -24,8 +24,9 @@
|
||||||
</h2>
|
</h2>
|
||||||
<p>Before you continue, make sure to check your email for our verification email. If you don't receive it within 24h drop us a line at <a href="mail:hi@medforms.com">hi@medforms.com</a></p>
|
<p>Before you continue, make sure to check your email for our verification email. If you don't receive it within 24h drop us a line at <a href="mail:hi@medforms.com">hi@medforms.com</a></p>
|
||||||
<div class="text-center form-group">
|
<div class="text-center form-group">
|
||||||
<button type="submit" class="btn btn-large btn-primary"><a href="/">Continue</a></button>
|
<button type="submit" class="btn btn-large btn-primary">
|
||||||
</div>
|
<a href="/">Continue</a>
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
|
@ -1,14 +1,14 @@
|
||||||
<section class="row text-center" data-ng-controller="VerifyController" ng-init="validateVerifyToken()">
|
<section class="row text-center" data-ng-controller="VerifyController" ng-init="validateVerifyToken()">
|
||||||
|
|
||||||
<section class="row text-center" ng-if="success">
|
<section class="row text-center" ng-if="isReset">
|
||||||
<h3 class="col-md-12">Password successfully reset</h3>
|
<h3 class="col-md-12">Password successfully reset</h3>
|
||||||
<a href="/#!/" class="col-md-12">Continue to home page</a>
|
<a href="/#!/" class="col-md-12">Continue to home page</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="row text-center" ng-if="!success">
|
<section class="row text-center" ng-if="!isReset">
|
||||||
<h3 class="col-md-12">Verification link is invalid or has expired</h3>
|
<h3 class="col-md-12">Verification link is invalid or has expired</h3>
|
||||||
<a href="/#!/verify" class="col-md-6">Resend your verification email</a>
|
<a href="/#!/verify" class="col-md-6">Resend your verification email</a>
|
||||||
<a href="/#!/signin" class="col-md-6">Signin to your account</a>
|
<a href="/#!/signin" class="col-md-6">Signin to your account</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</section>
|
</section>
|
20
test.js
20
test.js
|
@ -1,20 +0,0 @@
|
||||||
var nodemailer = require('nodemailer'),
|
|
||||||
config = require('./config/config');
|
|
||||||
console.log('Start script');
|
|
||||||
|
|
||||||
var transporter = nodemailer.createTransport(config.mailer.options);
|
|
||||||
|
|
||||||
var verifyMailOptions = {
|
|
||||||
to: '1nsphq+9hg2ghgtblstc@sharklasers.com',
|
|
||||||
from: 'Do Not Reply <user@gmail.com>',
|
|
||||||
subject: 'Confirm your account',
|
|
||||||
html: '<p>Please verify your account by clicking <a href="${URL}">this link</a>. If you are unable to do so, copy and ' +
|
|
||||||
'paste the following link into your browser:</p><p>${URL}</p>',
|
|
||||||
text: 'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
|
|
||||||
};
|
|
||||||
|
|
||||||
transporter.sendMail(verifyMailOptions , function(err, info){
|
|
||||||
if (err) console.log(err.message);
|
|
||||||
else console.log(info.response);
|
|
||||||
|
|
||||||
});
|
|
Loading…
Reference in a new issue