Skip to content

Commit fd5355c

Browse files
committed
add util aws. add function photo.fix invalid functions
1 parent 66e880c commit fd5355c

File tree

8 files changed

+255
-229
lines changed

8 files changed

+255
-229
lines changed

controllers/auth.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const passport = require('koa-passport');
2+
const config = require('config');
3+
const jwt = require('jwt-simple'); // аутентификация по JWT для hhtp
4+
const User = require('../models/User');
5+
6+
module.exports = {
7+
async signIn(ctx, next) {
8+
await passport.authenticate('local', (err, user) => {
9+
if (user) {
10+
const payload = {
11+
id: user._id,
12+
};
13+
ctx.body = {
14+
token: jwt.encode(payload, config.get('jwtSecret')),
15+
user: {
16+
email: user.email,
17+
},
18+
};
19+
} else {
20+
ctx.body = {
21+
err,
22+
};
23+
}
24+
})(ctx, next);
25+
},
26+
async signUp(ctx) {
27+
const {
28+
firstname,
29+
lastname,
30+
email,
31+
username,
32+
password,
33+
} = ctx.request.body;
34+
try {
35+
const Find = await User.find({
36+
email,
37+
});
38+
if (Find.length !== 0) {
39+
ctx.body = {
40+
err: 'Such person already exist',
41+
};
42+
} else {
43+
const newUser = new User({
44+
firstname,
45+
lastname,
46+
username,
47+
email,
48+
password,
49+
});
50+
await User.create(newUser);
51+
ctx.response.status = 200;
52+
}
53+
} catch (err) {
54+
ctx.response.status = 500;
55+
ctx.body = {
56+
err,
57+
};
58+
}
59+
},
60+
async checkEmail(ctx) {
61+
const {
62+
email,
63+
} = ctx.request.body;
64+
try {
65+
const Find = await User.find({
66+
email,
67+
});
68+
if (Find.length === 0) {
69+
ctx.body = {
70+
err: "Such person doesn't exist!",
71+
};
72+
} else {
73+
ctx.response.status = 200;
74+
}
75+
} catch (err) {
76+
ctx.body = {
77+
err,
78+
};
79+
}
80+
},
81+
async resetPass(ctx) {
82+
const {
83+
email,
84+
password,
85+
} = ctx.request.body;
86+
try {
87+
const Find = await User.find({
88+
email,
89+
});
90+
const user = Find[0];
91+
user.password = password;
92+
await user.save();
93+
ctx.response.status = 200;
94+
} catch (err) {
95+
ctx.body = {
96+
err,
97+
};
98+
}
99+
},
100+
}

controllers/index.js

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)