Browse Source

Added automatic login after register.

Kris 8 years ago
parent
commit
11c9b103cb
2 changed files with 20 additions and 6 deletions
  1. 9 3
      backend/logic/actions/users.js
  2. 11 3
      frontend/App.vue

+ 9 - 3
backend/logic/actions/users.js

@@ -63,8 +63,8 @@ module.exports = {
 
 	},
 
-	register: (session, username, email, password, recaptcha, cb) => {
-
+	register: function(session, username, email, password, recaptcha, cb) {
+		let _this = this;
 		async.waterfall([
 
 			// verify the request with google recaptcha
@@ -134,7 +134,13 @@ module.exports = {
 				return cb({ status: 'error', message: 'An error occurred while registering for an account' });
 			}
 			// respond with the payload that was passed to us earlier
-			cb(payload);
+			_this.login(session, email, password, (result) => {
+				let obj = { status: 'success', message: 'Successfully registered.' };
+				if (result.status === 'success') {
+					obj.SID = result.SID;
+				}
+				cb(obj);
+			});
 		});
 
 	},

+ 11 - 3
frontend/App.vue

@@ -62,9 +62,17 @@
 				let { register: { email, username, password } } = this;
 				let _this = this;
 				this.socket.emit('users.register', username, email, password, /*grecaptcha.getResponse()*/null, result => {
-					Toast.methods.addToast(`User ${username} has been registered`, 2000);
-					_this.$router.go('/');
-					location.reload();
+					Toast.methods.addToast(`You have successfully registered.`, 4000);
+					setTimeout(() => {
+						if (result.SID) {
+							let date = new Date();
+							date.setTime(new Date().getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
+							document.cookie = `SID=${result.SID}; expires=${date.toGMTString()}; path=/`;
+							location.reload();
+						} else {
+							_this.$router.go('/login');
+						}
+					}, 4000);
 				});
 			},
 			'login': function () {