Permalink
Browse files

Refactor and advancements

- Drops mailController, centralized in UserController
- Adds views folder for change_password
- Improves PromiseRouter to support text results
- Improves PromiseRouter to support empty responses for redirects
- Adds options to AdaptableController
- UsersController gracefully fails when no adapter is set
- Refactors GlobalConfig into same style for Routers
  • Loading branch information...
1 parent 7dd7652 commit f3bb2c99e0250c0ae2e1dce457b581c7f2f6ff31 @flovilmart flovilmart committed Feb 27, 2016
@@ -1,3 +1,5 @@
module.exports = {
- sendVerificationEmail: () => Promise.resolve();
+ sendVerificationEmail: () => Promise.resolve(),
+ sendPasswordResetEmail: () => Promise.resolve(),
+ sendMail: () => Promise.resolve()
}
@@ -4,6 +4,7 @@ module.exports = options => {
}
return {
sendVerificationEmail: () => Promise.resolve(),
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve()
}
}
@@ -2,13 +2,12 @@
var request = require('request');
var Parse = require('parse/node').Parse;
-var DatabaseAdapter = require('../src/DatabaseAdapter');
-
-let database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
+let Config = require('../src/Config');
describe('a GlobalConfig', () => {
beforeEach(function(done) {
- database.rawCollection('_GlobalConfig')
+ let config = new Config('test');
+ config.database.rawCollection('_GlobalConfig')
.then(coll => coll.updateOne({ '_id': 1}, { $set: { params: { companies: ['US', 'DK'] } } }, { upsert: true }))
.then(done());
});
@@ -61,7 +60,8 @@ describe('a GlobalConfig', () => {
});
it('failed getting config when it is missing', (done) => {
- database.rawCollection('_GlobalConfig')
+ let config = new Config('test');
+ config.database.rawCollection('_GlobalConfig')
.then(coll => coll.deleteOne({ '_id': 1}, {}, {}))
.then(_ => {
request.get({
@@ -52,6 +52,7 @@ describe('Parse.User testing', () => {
it('sends verification email if email verification is enabled', done => {
var emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve()
}
setServerConfiguration({
@@ -91,6 +92,7 @@ describe('Parse.User testing', () => {
it('does not send verification email if email verification is disabled', done => {
var emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve()
}
setServerConfiguration({
@@ -134,6 +136,7 @@ describe('Parse.User testing', () => {
expect(options.user.get('email')).toEqual('user@parse.com');
done();
},
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {}
}
setServerConfiguration({
@@ -176,9 +179,14 @@ describe('Parse.User testing', () => {
.then(() => {
expect(user.get('emailVerified')).toEqual(true);
done();
+ }, (err) => {
+ console.error(err);
+ fail("this should not fail");
+ done();
});
});
},
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {}
}
setServerConfiguration({
@@ -237,6 +245,7 @@ describe('Parse.User testing', () => {
});
});
},
+ sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {}
}
setServerConfiguration({
@@ -270,6 +279,11 @@ describe('Parse.User testing', () => {
success: function(user) {
Parse.User.logIn("non_existent_user", "asdf3",
expectError(Parse.Error.OBJECT_NOT_FOUND, done));
+ },
+ error: function(err) {
+ console.error(err);
+ fail("Shit should not fail");
+ done();
}
});
});
@@ -0,0 +1,36 @@
+
+var request = require('request');
+
+
+describe("public API", () => {
+
+ it("should get invalid_link.html", (done) => {
+ request('http://localhost:8378/1/apps/invalid_link.html', (err, httpResponse, body) => {
+ expect(httpResponse.statusCode).toBe(200);
+ done();
+ });
+ });
+
+ it("should get choose_password", (done) => {
+ request('http://localhost:8378/1/apps/choose_password', (err, httpResponse, body) => {
+ expect(httpResponse.statusCode).toBe(200);
+ done();
+ });
+ });
+
+ it("should get verify_email_success.html", (done) => {
+ request('http://localhost:8378/1/apps/verify_email_success.html', (err, httpResponse, body) => {
+ expect(httpResponse.statusCode).toBe(200);
+ done();
+ });
+ });
+
+ it("should get password_reset_success.html", (done) => {
+ request('http://localhost:8378/1/apps/password_reset_success.html', (err, httpResponse, body) => {
+ expect(httpResponse.statusCode).toBe(200);
+ done();
+ });
+ });
+
+
+})
@@ -1,5 +1,6 @@
export class MailAdapter {
sendVerificationEmail(options) {}
+ sendPasswordResetEmail(options) {}
sendMail(options) {}
}
@@ -37,6 +37,19 @@ let SimpleMailgunAdapter = mailgunOptions => {
text: verifyMessage
});
},
+
+ sendPasswordResetEmail: ({link,user, appName}) => {
+ let message =
+ "Hi,\n\n" +
+ "You requested to reset your password for " + appName + ".\n\n" +
+ "" +
+ "Click here to reset it:\n" + link;
+ return sendMail({
+ to:user.email,
+ subject: 'Password Reset for ' + appName,
+ text: message
+ });
+ },
sendMail: sendMail
});
}
View
@@ -24,8 +24,6 @@ export class Config {
this.allowClientClassCreation = cacheInfo.allowClientClassCreation;
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, cacheInfo.collectionPrefix);
- this.mailController = cacheInfo.mailController;
-
this.serverURL = cacheInfo.serverURL;
this.verifyUserEmails = cacheInfo.verifyUserEmails;
this.appName = cacheInfo.appName;
@@ -34,7 +32,7 @@ export class Config {
this.filesController = cacheInfo.filesController;
this.pushController = cacheInfo.pushController;
this.loggerController = cacheInfo.loggerController;
- this.mailController = cacheInfo.mailController;
+ this.userController = cacheInfo.userController;
this.oauth = cacheInfo.oauth;
this.mount = mount;
@@ -49,7 +47,11 @@ export class Config {
}
get choosePasswordURL() {
- return `${this.serverURL}/apps/choose_password`;
+ return `${this.serverURL}/apps/${this.applicationId}/choose_password`;
+ }
+
+ get requestResetPasswordURL() {
+ return `${this.serverURL}/apps/${this.applicationId}/request_password_reset`;
}
get passwordResetSuccessURL() {
@@ -10,11 +10,12 @@ based on the parameters passed
// _adapter is private, use Symbol
var _adapter = Symbol();
-import cache from '../cache';
+import Config from '../Config';
export class AdaptableController {
- constructor(adapter, appId) {
+ constructor(adapter, appId, options) {
+ this.options = options;
this.adapter = adapter;
this.appId = appId;
}
@@ -29,7 +30,7 @@ export class AdaptableController {
}
get config() {
- return cache.apps[this.appId];
+ return new Config(this.appId);
}
expectedAdapterType() {
@@ -1,30 +0,0 @@
-import AdaptableController from './AdaptableController';
-import { MailAdapter } from '../Adapters/Email/MailAdapter';
-import { randomString } from '../cryptoUtils';
-import { inflate } from '../triggers';
-
-export class MailController extends AdaptableController {
- setEmailVerificationStatus(user, status) {
- if (status == false) {
- user._email_verify_token = randomString(25);
- }
- user.emailVerified = status;
- }
- sendVerificationEmail(user, config) {
- const token = encodeURIComponent(user._email_verify_token);
- const username = encodeURIComponent(user.username);
-
- let link = `${config.verifyEmailURL}?token=${token}&username=${username}`;
- this.adapter.sendVerificationEmail({
- appName: config.appName,
- link: link,
- user: inflate('_User', user),
- });
- }
- sendMail(options) {
- this.adapter.sendMail(options);
- }
- expectedAdapterType() {
- return MailAdapter;
- }
-}
Oops, something went wrong.

0 comments on commit f3bb2c9

Please sign in to comment.