Пример #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            try
            {
                GetEmployeesList();
                GetRolesList();

                if (ModelState.IsValid)
                {
                    if (!(model.Email.ToLower().EndsWith("@agilisium.com") || model.Email.ToLower().EndsWith("@agileiss.com")))
                    {
                        DisplayWarningMessage("Please use Agilisium Email ID to register");
                        return(View(model));
                    }

                    ApplicationUser user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        EmployeeLoginMappingDto mapping = new EmployeeLoginMappingDto
                        {
                            EmployeeID     = model.EmployeeID,
                            LoginUserID    = user.Id,
                            RoleID         = model.RoleID,
                            LoginUserEmail = model.Email
                        };
                        userService.Add(mapping);
                    }
                    //return RedirectToAction("List", "ELogin");

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    //    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    AddErrors(result);

                    return(RedirectToAction("List", "ELogin"));
                    //}
                }
            }
            catch (Exception exp)
            {
                DisplayUpdateErrorMessage(exp);
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }