Esempio n. 1
0
 public virtual ActionResult AddProfile(Profile profile)
 {
     if (ModelState.IsValid)
     {
         if ((profile.Avatar == null) || (profile.Avatar.Length == 0))
         {
             profile.Avatar = "profilepicture.png";
         }
         _profileService.AddNewProfile(profile);
         _uow.SaveChanges();
         return(RedirectToAction("Index", "Cartable", new { area = "UserArea" }));
     }
     return(View(profile));
 }
Esempio n. 2
0
        public async Task <IActionResult> Registration(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var(result, userId, code) = await _identityService.CreateUserAsync(model.Email, model.UserName, model.Password);

                    if (result == null)
                    {
                        ModelState.AddModelError(string.Empty, ErrorConstants.RegistrationEmailExist);
                        _logger.LogInformation($"Problem with registration {model.UserName} on the server side.");

                        return(BadRequest(model));
                    }

                    if (result.Succeeded)
                    {
                        await _profileService.AddNewProfile(model.UserName, userId);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId, code }, protocol: HttpContext.Request.Scheme);

                        var email = new Email
                        {
                            UserName = model.UserName,
                            Code     = callbackUrl
                        };

                        var body = await _razorViewToString.RenderViewToStringAsync("Views/Email/Confirm.cshtml", email);

                        await _emailService.SendEmailAsync(model.Email, ErrorConstants.AccountConfirm, body);

                        _logger.LogInformation($"New user {model.UserName}");

                        return(Ok());
                    }
                }
                catch (Exception e)
                {
                    _logger.LogInformation($"{e.Message} when user registration");
                }

                return(BadRequest(model));
            }

            return(BadRequest(model));
        }