public async Task <ActionResult> CreateStudent([FromBody] StudentRegisterDTO newStudent) { newStudent.Password = AuthentificationService.EncryptPassword(newStudent.Password); string base64Image = newStudent.Student.ProfilePicturePath; if (!string.IsNullOrEmpty(base64Image)) { string imageFileId = await _sharedRepository.GetNextImageId(); newStudent.Student.ProfilePicturePath = FileManagerService.SaveImageToFile(base64Image, imageFileId); } if (await _repository.CreateNonExistingStudent(newStudent)) { StudentDTO student = await _repository.StudentExists(newStudent.Student.Email); student.Student.ProfilePicturePath = base64Image; string token = JwtManager.GenerateJWToken(student.Student, student.Id.ToString()); return(Ok(new JsonResult(token))); } else { return(Ok(new JsonResult("Email taken"))); } }
public async Task <ActionResult> AddEditor([FromBody] EditorRegisterDTO editorInfo) { if (!await _repository.EditorExists(editorInfo.Username)) { editorInfo.Password = PasswordEncriptionService.EncryptPassword(editorInfo.Password); Editor editor = _mapper.Map <Editor>(editorInfo); await _repository.AddEditor(editor); var token = JwtManager.GenerateJWToken(editor); return(Ok(new JsonResult(token))); } else { return(Ok(new JsonResult("Email taken"))); } }
public async Task <ActionResult> LogEditorIn([FromBody] EditorLoginDTO editorCredentials) { string savedPwd = await _repository.GetEditorPassword(editorCredentials.Username); if (savedPwd != null) { if (PasswordEncriptionService.IsPasswordCorrect(savedPwd, editorCredentials.Password)) { Editor editor = await _repository.GetEditorByUsername(editorCredentials.Username); string token = JwtManager.GenerateJWToken(editor); return(Ok(new JsonResult(token))); } else { return(Ok(new JsonResult("Wrong password"))); } } else { return(Ok(new JsonResult("Non-existent username"))); } }
public async Task <ActionResult> LogUserIn([FromBody] AccountLogInDTO userCredentials) { string savedPwd = await _repository.GetPassword(userCredentials.Email); if (savedPwd != null) { if (AuthentificationService.IsPasswordCorrect(savedPwd, userCredentials.Password)) { StudentDTO student = await _repository.StudentExists(userCredentials.Email); student.Student.ProfilePicturePath = FileManagerService.LoadImageFromFile(student.Student.ProfilePicturePath); string token = JwtManager.GenerateJWToken(student.Student, student.Id.ToString()); return(Ok(new JsonResult(token))); } else { return(Ok(new JsonResult("Wrong password"))); } } else { return(Ok(new JsonResult("Non-existent email"))); } }