Example #1
0
        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")));
            }
        }
Example #2
0
        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")));
            }
        }