|
@@ -45,7 +45,7 @@ const saveAvatarForStatic = async (req, res, next) => {
|
|
|
|
|
|
const createNewUser = async (req, res, next) => {
|
|
const createNewUser = async (req, res, next) => {
|
|
try {
|
|
try {
|
|
- const code = phoneToken(8, { type: 'number' });
|
|
|
|
|
|
+ const code = phoneToken(4, { type: 'number' });
|
|
const { number, country } = req.body;
|
|
const { number, country } = req.body;
|
|
const isExist = await UserModel.findByNumber(number);
|
|
const isExist = await UserModel.findByNumber(number);
|
|
if (isExist) {
|
|
if (isExist) {
|
|
@@ -73,13 +73,7 @@ const logIn = async (req, res, next) => {
|
|
try {
|
|
try {
|
|
const { number, code } = req.body;
|
|
const { number, code } = req.body;
|
|
const user = await UserModel.findByNumber(number);
|
|
const user = await UserModel.findByNumber(number);
|
|
- if (
|
|
|
|
- !user ||
|
|
|
|
- user.code !== code ||
|
|
|
|
- !user.name ||
|
|
|
|
- !user.lastName ||
|
|
|
|
- !user.avatarUrl
|
|
|
|
- )
|
|
|
|
|
|
+ if (!user || user.code !== code)
|
|
return res.status(401).json({
|
|
return res.status(401).json({
|
|
status: 'error',
|
|
status: 'error',
|
|
code: 401,
|
|
code: 401,
|
|
@@ -90,6 +84,7 @@ const logIn = async (req, res, next) => {
|
|
const id = user._id;
|
|
const id = user._id;
|
|
const payload = { id };
|
|
const payload = { id };
|
|
const token = jwt.sign(payload, SECRET_KEY, { expiresIn: '24h' });
|
|
const token = jwt.sign(payload, SECRET_KEY, { expiresIn: '24h' });
|
|
|
|
+ const registration = user.name? false: true
|
|
await UserModel.updateToken(id, token);
|
|
await UserModel.updateToken(id, token);
|
|
await UserModel.updateCode(id, '');
|
|
await UserModel.updateCode(id, '');
|
|
return res.status(200).json({
|
|
return res.status(200).json({
|
|
@@ -97,6 +92,7 @@ const logIn = async (req, res, next) => {
|
|
code: 200,
|
|
code: 200,
|
|
data: {
|
|
data: {
|
|
token,
|
|
token,
|
|
|
|
+ registration
|
|
},
|
|
},
|
|
});
|
|
});
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -145,12 +141,13 @@ const getCurrent = async (req, res, next) => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-const updateName = async (req, res, next) => {
|
|
|
|
|
|
+const updateCredentials = async (req, res, next) => {
|
|
try {
|
|
try {
|
|
const id = req.user.id;
|
|
const id = req.user.id;
|
|
- const user = await UserModel.updateName(id, req.body.name);
|
|
|
|
|
|
+ const user = await UserModel.updateCredentials(id, req.body);
|
|
return res.status(200).json({
|
|
return res.status(200).json({
|
|
- data: user,
|
|
|
|
|
|
+ data: {
|
|
|
|
+ user},
|
|
});
|
|
});
|
|
} catch (e) {
|
|
} catch (e) {
|
|
next(e);
|
|
next(e);
|
|
@@ -163,5 +160,5 @@ module.exports = {
|
|
logIn,
|
|
logIn,
|
|
logOut,
|
|
logOut,
|
|
getCurrent,
|
|
getCurrent,
|
|
- updateName,
|
|
|
|
|
|
+ updateCredentials,
|
|
};
|
|
};
|