-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jhonatancunha/development
Subindo versão estável com login com Google Versão 2.0.0
- Loading branch information
Showing
92 changed files
with
9,884 additions
and
6,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
backend/src/app/controllers/Student/LDAPSessionStudentController.js
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
backend/src/app/controllers/Student/SessionStudentController.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,65 @@ | ||
import * as Yup from 'yup'; | ||
import GenerateTokenProvider from '../../provider/GenerateTokenProvider'; | ||
import GenerateRefreshTokenProvider from '../../provider/GenerateRefreshTokenProvider'; | ||
import StudentRepository from '../../repositories/Student'; | ||
import DeleteRefreshTokenService from '../RefreshToken/DeleteRefreshToken'; | ||
import GenerateRefreshTokenProvider from '../../provider/GenerateRefreshTokenProvider'; | ||
import GenerateTokenProvider from '../../provider/GenerateTokenProvider'; | ||
|
||
class CreateStudentService { | ||
class StudentSessionService { | ||
constructor() { | ||
this.studentRepository = new StudentRepository(); | ||
} | ||
|
||
async execute(data) { | ||
const { name, email, picture, isLocalImage } = data; | ||
|
||
const schema = Yup.object().shape({ | ||
name: Yup.string().required(), | ||
email: Yup.string().email().required(), | ||
password: Yup.string().required(), | ||
picture: Yup.string().required(), | ||
isLocalImage: Yup.boolean().required(), | ||
}); | ||
|
||
if (!(await schema.isValid(data))) { | ||
const error = new Error(); | ||
error.response = 'Falha na validação!'; | ||
error.status = 403; | ||
error.response = 'Falha na validação!'; | ||
throw error; | ||
} | ||
|
||
if ( | ||
await this.studentRepository.findOne({ where: { email: data.email } }) | ||
) { | ||
const error = new Error(); | ||
error.status = 403; | ||
error.response = 'E-mail já cadastrado!'; | ||
throw error; | ||
let student = await this.studentRepository.findOne({ | ||
where: { email }, | ||
}); | ||
|
||
if (!student) { | ||
const idImage = isLocalImage ? picture : null; | ||
const urlImage = !isLocalImage ? picture : null; | ||
|
||
student = await this.studentRepository.create({ | ||
email, | ||
name, | ||
idImage, | ||
urlImage, | ||
isLocalImage, | ||
}); | ||
} | ||
|
||
const student = await this.studentRepository.create(data); | ||
const { id, email, name } = student; | ||
const { id } = student; | ||
|
||
// REMOVE REFRESH TOKENS ANTIGOS SALVOS NO BANCO | ||
await DeleteRefreshTokenService.execute({ | ||
where: { userId: id }, | ||
}); | ||
|
||
const token = await GenerateTokenProvider.execute(id); | ||
|
||
const refreshToken = await GenerateRefreshTokenProvider.execute(id); | ||
|
||
return { | ||
student: { | ||
email, | ||
name, | ||
}, | ||
student, | ||
token, | ||
refreshToken: refreshToken.id, | ||
isFirstLogin: !name, | ||
}; | ||
} | ||
} | ||
|
||
export default new CreateStudentService(); | ||
export default new StudentSessionService(); |
Oops, something went wrong.