Пример #1
0
        public async Task <ActionResult <ItemResponse <int> > > CreateAsyncV2(UserAddRequestV2 userAddRequest)
        {
            ObjectResult result = null;

            try
            {
                Guid token = Guid.NewGuid();

                int userId = _userService.CreateV2(userAddRequest, token);
                if (userId != 0)
                {
                    EmailResponse item = await _emailService.ConfirmEmail(userAddRequest.Email, token);

                    ItemResponse <int> response = new ItemResponse <int> {
                        Item = userId
                    };
                    result = Created201(response);
                }
            }
            catch (Exception ex)
            {
                base.Logger.LogError(ex.ToString());
                ErrorResponse response = new ErrorResponse(ex.Message);
                result = StatusCode(500, response);
            }

            return(result);
        }
        public async Task <IActionResult> ConfirmEmail(string tokenEmail)
        {
            if (tokenEmail == null)
            {
                return(BadRequest(new
                {
                    message = "can't access like that !",
                    is_erro = true
                }));
            }
            var result = await _emailService.ConfirmEmail(tokenEmail);

            if (result)
            {
                return(Ok(new
                {
                    message = "Your email has confirm !",
                    is_erro = false
                }));
            }
            else
            {
                return(BadRequest(new
                {
                    message = "can't confirm email, something wrong !",
                    is_erro = true
                }));
            }
        }
Пример #3
0
        public IActionResult ConfirmEmail([FromBody] string codeConfirmEmail)
        {
            if (_emailService.ConfirmEmail(codeConfirmEmail))
            {
                return(Ok());
            }

            return(BadRequest());
        }
Пример #4
0
        private async Task SendConfirmationEmailAsync(string email, string cTokenLink)
        {
            var appUser = await _userManager.FindByEmailAsync(email);

            string message = await _viewRenderService.RenderToStringAsync("ConfirmEmailTemplate", email);

            message = message.Replace("{username}", appUser.UserName);
            message = message.Replace("{email}", appUser.Email);
            message = message.Replace("{confirmLink}", cTokenLink);
            var jobId = BackgroundJob.Enqueue(
                () => _emailService.ConfirmEmail(appUser.Email, message));
        }
Пример #5
0
        public async Task <IActionResult> ConfirmEmail(string id, string code)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Result result = await _emailService.ConfirmEmail(id, code);

            if (result.Failure)
            {
                ModelState.AddErrors(result.Errors);
                return(View());
            }

            return(View());
        }
Пример #6
0
        public async Task <ActionResult <ItemResponse <EmailResponse> > > ConfirmEmail(string email)
        {
            int          code     = 200;
            BaseResponse response = null;

            try
            {
                Guid          token = new Guid();
                EmailResponse item  = await _service.ConfirmEmail(email, token);

                response = new SuccessResponse();
            }
            catch (Exception ex)
            {
                code     = 500;
                response = new ErrorResponse(ex.Message);
            }

            return(StatusCode(code, response));
        }
Пример #7
0
        public async Task <ActionResult> Register(UserAddRequest model)
        {
            ObjectResult result = null;

            try
            {
                int id = _userService.Create(model);

                Guid guid = Guid.NewGuid();

                _userTokenService.Add(id, guid);

                EmailAddRequest emailBase = new EmailAddRequest();
                emailBase.From = model.Email;
                string email       = emailBase.From;
                string directory   = Environment.CurrentDirectory;
                string path        = Path.Combine(directory, "EmailTemplates\\ConfirmEmail.html");
                string htmlContent = System.IO.File.ReadAllText(path);
                await _service.ConfirmEmail(email, htmlContent, _sendGridConfig.Secret, _sendGridConfig.Email, guid);

                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };

                result = Created201(response);
            }
            catch (Exception ex)
            {
                base.Logger.LogError(ex.ToString());

                ErrorResponse response = new ErrorResponse(ex.Message);

                result = StatusCode(500, response);
            }
            return(result);
        }