Skip to content
This repository was archived by the owner on Jul 4, 2018. It is now read-only.

Commit 0adb06c

Browse files
authored
Merge pull request #64 from FoalTS/v0-4-0-beta-4
v0.4.0-beta.4
2 parents bb315cd + 2303fe5 commit 0adb06c

22 files changed

+88
-113
lines changed

generators/app/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Welcome to the FoalTS generator! The following questions will help you create yo
4242
{ name: 'None', value: null },
4343
{ name: 'SQLite', value: 'sqlite' },
4444
{ name: 'PostgreSQL', value: 'postgres' },
45+
{ name: 'Microsoft SQL Server', value: 'mssql' },
4546
// { name: 'MySQL', value: 'mysql' },
4647
],
4748
default: 'sqlite'
@@ -79,7 +80,7 @@ Welcome to the FoalTS generator! The following questions will help you create yo
7980
name: 'type',
8081
message: 'Which authenticator do you want to use?',
8182
choices: [
82-
choice('Local authenticator (with email and password)', 'local-authenticator'),
83+
choice('Email and password authenticator', 'email-and-password-authenticator'),
8384
// choice('I\'ll create one on my own.', 'authenticator')
8485
],
8586
default: 0
@@ -152,7 +153,6 @@ Welcome to the FoalTS generator! The following questions will help you create yo
152153
'src/app/auth/index.ts',
153154
'src/app/auth/login-view.service.spec.ts',
154155
'src/app/auth/login-view.service.ts',
155-
'src/app/shared/user.interface.ts',
156156
'src/app/shared/user.service.ts',
157157
);
158158
}
@@ -182,17 +182,20 @@ Welcome to the FoalTS generator! The following questions will help you create yo
182182
let dbDependencies = [];
183183
switch(this.database) {
184184
case 'sqlite':
185-
dbDependencies.push('@foal/sequelize@0.4.0-beta.2', 'sqlite3');
185+
dbDependencies.push('@foal/sequelize@0.4.0-beta.3', 'sqlite3');
186186
break;
187187
case 'postgres':
188-
dbDependencies.push('@foal/sequelize@0.4.0-beta.2', 'pg@6', 'pg-hstore');
188+
dbDependencies.push('@foal/sequelize@0.4.0-beta.3', 'pg@6', 'pg-hstore');
189+
break;
190+
case 'mssql':
191+
dbDependencies.push('@foal/sequelize@0.4.0-beta.3', 'tedious');
189192
break;
190193
case 'mysql':
191-
dbDependencies.push('@foal/sequelize@0.4.0-beta.2', 'mysql2');
194+
dbDependencies.push('@foal/sequelize@0.4.0-beta.3', 'mysql2');
192195
break;
193196
}
194197
if (this.authentication) {
195-
dbDependencies.push('@foal/authentication@0.4.0-beta.2', 'bcrypt-nodejs');
198+
dbDependencies.push('@foal/authentication@0.4.0-beta.3');
196199
}
197200
if (dbDependencies.length !== 0) {
198201
this.npmInstall(dbDependencies, {}, () => {}, { cwd: this.names.kebabName });

generators/app/templates/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"express-session": "^1.15.6",
2323
"helmet": "^3.9.0",
2424
"@types/node": "^8.0.47",
25-
"@foal/ajv": "^0.4.0-beta.1",
26-
"@foal/common": "^0.4.0-beta.2",
27-
"@foal/core": "^0.4.0-beta.1",
28-
"@foal/ejs": "^0.4.0-beta.2",
29-
"@foal/express": "^0.4.0-beta.1",
25+
"@foal/ajv": "^0.4.0-beta.3",
26+
"@foal/common": "^0.4.0-beta.3",
27+
"@foal/core": "^0.4.0-beta.3",
28+
"@foal/ejs": "^0.4.0-beta.3",
29+
"@foal/express": "^0.4.0-beta.3",
3030
"source-map-support": "^0.5.1"
3131
},
3232
"devDependencies": {

generators/app/templates/src/app/auth/auth.module.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
import { validate } from '@foal/ajv';
2-
import { authentication } from '@foal/authentication';
3-
import { basic, HttpResponseRedirect, Module } from '@foal/core';
4-
1+
import { authentication, validateEmailAndPasswordCredentialsFormat } from '@foal/authentication';
52
import { view } from '@foal/common';
3+
import { Module } from '@foal/core';
4+
65
import { AuthenticatorService } from './authenticator.service';
76
import { LoginViewService } from './login-view.service';
87

98
export const AuthModule: Module = {
109
controllers: [
1110
authentication
12-
.attachService('/local', AuthenticatorService, {
11+
.attachService('/email', AuthenticatorService, {
1312
failureRedirect: '/auth?invalid_credentials=true', // Optional
1413
successRedirect: '/whatever_you_like', // Optional
1514
})
16-
.withPreHook(validate({
17-
additionalProperties: false,
18-
properties: {
19-
email: { type: 'string', format: 'email' },
20-
password: { type: 'string' }
21-
},
22-
required: [ 'email', 'password' ],
23-
type: 'object',
24-
})),
25-
basic
26-
.attachHandlingFunction('POST', 'logout', ctx => {
27-
delete ctx.session.authentication;
28-
return new HttpResponseRedirect('/auth');
29-
}),
15+
.withPreHook(validateEmailAndPasswordCredentialsFormat()),
16+
authentication
17+
.attachLogout('/logout', { redirect: '/auth' }),
3018
view
3119
.attachService('/', LoginViewService)
3220
.withPreHook(ctx => {

generators/app/templates/src/app/auth/authenticator.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { LocalAuthenticatorService } from '@foal/authentication';
1+
import { EmailAndPasswordAuthenticatorService } from '@foal/authentication';
22
import { Service } from '@foal/core';
33

44
import { User, UserService } from '../shared';
55

66
@Service()
7-
export class AuthenticatorService extends LocalAuthenticatorService<User> {
7+
export class AuthenticatorService extends EmailAndPasswordAuthenticatorService<User> {
88
constructor(userService: UserService) {
99
super(userService);
1010
}

generators/app/templates/src/app/auth/login-view.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const template1 =
1212
<title>Login</title>
1313
</head>
1414
<body>
15-
<form action="/auth/local" method="post">
15+
<form action="/auth/email" method="post">
1616
<input type="hidden" name="_csrf" value="foobar">
1717
<input type="email" name="email" required autofocus>
1818
<br>
@@ -32,7 +32,7 @@ const template2 =
3232
<title>Login</title>
3333
</head>
3434
<body>
35-
<form action="/auth/local" method="post">
35+
<form action="/auth/email" method="post">
3636
<strong>Invalid credentials.</strong>
3737
<input type="hidden" name="_csrf" value="foobar">
3838
<input type="email" name="email" required autofocus>

generators/app/templates/src/app/auth/templates/login-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</style>
1919
</head>
2020
<body>
21-
<form class="text-center" action="/auth/local" method="post">
21+
<form class="text-center" action="/auth/email" method="post">
2222
<h1 class="h3 mb-4">Log in</h1><% if (invalidCredentials) { %>
2323
<div class="alert alert-danger">
2424
<strong>Invalid credentials.</strong>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export { ConnectionService } from './connection.service';<% if (authentication) { %>
2-
export { User } from './user.interface';
3-
export { UserService } from './user.service';<% } %>
2+
export { User, UserService } from './user.service';<% } %>

generators/app/templates/src/app/shared/user.interface.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
import { CheckPassword } from '@foal/authentication';
1+
import {
2+
BaseUser,
3+
EmailAndPassword,
4+
emailAndPasswordSchema,
5+
parsePassword,
6+
UserModelService,
7+
} from '@foal/authentication';
28
import { Service } from '@foal/core';
3-
import { DefaultIdAndTimeStamps, Sequelize, SequelizeModelService } from '@foal/sequelize';
4-
import * as bcrypt from 'bcrypt-nodejs';
59

610
import { ConnectionService } from './connection.service';
7-
import { User } from './user.interface';
11+
12+
export type User = BaseUser & EmailAndPassword;
813

914
@Service()
10-
export class UserService extends SequelizeModelService<User> implements CheckPassword<User> {
11-
constructor(connection: ConnectionService) {
12-
super('users', {
13-
email: { type: Sequelize.STRING, unique: true, allowNull: false },
14-
isAdmin: { type: Sequelize.BOOLEAN, allowNull: false },
15-
password: { type: Sequelize.STRING, allowNull: false },
16-
}, connection);
17-
}
15+
export class UserService extends UserModelService<User> {
1816

19-
public createOne(data: User): Promise<User & DefaultIdAndTimeStamps> {
20-
return super.createOne({
21-
...data,
22-
password: bcrypt.hashSync(data.password)
23-
});
17+
constructor(connection: ConnectionService) {
18+
super(emailAndPasswordSchema, connection, [ parsePassword ]);
2419
}
2520

26-
public checkPassword(user: User, password: string): boolean {
27-
return bcrypt.compareSync(password, user.password);
28-
}
2921
}

generators/app/templates/src/config/config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { ObjectType } from '@foal/core';
2-
3-
export interface Config extends ObjectType {
1+
export interface Config {
42
app: {
53
name: string;
64
};
75
csrfProtection: boolean;
86
db: {
9-
options: ObjectType;
7+
options: any;
108
uri: string;
119
};
1210
debugMode: boolean;

0 commit comments

Comments
 (0)