public void Create(InstallModel model)
        {
            var user = new User
            {
                Email    = model.AdminEmail,
                IsActive = true
            };

            _passwordManagementService.SetPassword(user, model.AdminPassword, model.ConfirmPassword);

            _userManagementService.AddUser(user);
            CurrentRequestData.CurrentUser = user;

            var adminUserRole = new UserRole
            {
                Name = UserRole.Administrator
            };

            user.Roles = new HashSet <UserRole> {
                adminUserRole
            };
            adminUserRole.Users = new HashSet <User> {
                user
            };

            _roleService.SaveRole(adminUserRole);
            _authorisationService.Logout();
            _authorisationService.SetAuthCookie(user, true);
        }
示例#2
0
        public async Task LoginAsync(ExternalLoginInfo externalLoginInfo, AuthenticateResult authenticateResult)
        {
            User user = await _userManager.FindAsync(externalLoginInfo.Login);

            await _authorisationService.SetAuthCookie(user, false);

            await _authorisationService.UpdateClaimsAsync(user, authenticateResult.Identity.Claims);
        }
示例#3
0
        public async Task Login(User user, bool rememberMe)
        {
            var previousSession = CurrentRequestData.UserGuid;
            await _authorisationService.SetAuthCookie(user, rememberMe);

            CurrentRequestData.CurrentUser = user;
            EventContext.Instance.Publish <IOnUserLoggedIn, UserLoggedInEventArgs>(new UserLoggedInEventArgs(user, previousSession));
        }
示例#4
0
        public async Task <RedirectResult> UserAccountDetails_POST(UserAccountModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var user = CurrentRequestData.CurrentUser;
                if (user != null && user.IsActive)
                {
                    user.FirstName = model.FirstName;
                    user.LastName  = model.LastName;
                    user.Email     = model.Email;
                    _userManagementService.SaveUser(user);
                    await _authorisationService.SetAuthCookie(user, false);

                    return(Redirect(UniquePageHelper.GetUrl <UserAccountPage>()));
                }
            }
            return(Redirect(UniquePageHelper.GetUrl <UserAccountPage>()));
        }
示例#5
0
        public async Task <User> RegisterUser(RegisterModel model)
        {
            var guid = CurrentRequestData.UserGuid;
            var user = new User
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Email     = model.Email,
                IsActive  = true
            };

            _passwordManagementService.SetPassword(user, model.Password, model.ConfirmPassword);
            _userService.AddUser(user);
            await _authorisationService.SetAuthCookie(user, false);

            CurrentRequestData.CurrentUser = user;
            EventContext.Instance.Publish <IOnUserRegistered, OnUserRegisteredEventArgs>(new OnUserRegisteredEventArgs(user, guid));
            return(user);
        }
示例#6
0
        public async Task <RedirectResult> UpdateUserInfo(UserAccountModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var user = CurrentRequestData.CurrentUser;
                if (user != null && user.IsActive)
                {
                    user.FirstName = model.FirstName;
                    user.LastName  = model.LastName;
                    user.Email     = model.Email;

                    _userService.SaveUser(user);
                    await _authorisationService.SetAuthCookie(user, false);

                    TempData.SuccessMessages().Add("User Info Updated");
                    return(_uniquePageService.RedirectTo <UserAccountInfo>());
                }
            }
            return(_uniquePageService.RedirectTo <LoginPage>());
        }
示例#7
0
        public ActionResult RegistrationWithoutDetails(RegisterWithoutDetailsModel model)
        {
            if (CurrentRequestData.CurrentUser != null)
            {
                return(Redirect(UniquePageHelper.GetUrl <ProductSearch>()));
            }

            if (model != null && ModelState.IsValid)
            {
                var existingUser = _userLookup.GetUserByEmail(model.Email);
                if (existingUser != null)
                {
                    return(Redirect(UniquePageHelper.GetUrl <ProductSearch>()));
                }


                var user = new User
                {
                    FirstName = String.Empty,
                    LastName  = String.Empty,
                    Email     = model.Email.Trim(),
                    IsActive  = true
                };

                _passwordManagementService.SetPassword(user, model.Password, model.Password);
                _userManagementService.AddUser(user);
                _authorisationService.SetAuthCookie(user, false);
                CurrentRequestData.CurrentUser = user;

                var order = _orderService.AssignUserToOrder(model.OrderId, user);
                if (order.BillingAddress != null)
                {
                    user.FirstName = order.BillingAddress.FirstName;
                    user.LastName  = order.BillingAddress.LastName;
                    _userManagementService.SaveUser(user);
                }

                return(Redirect(UniquePageHelper.GetUrl <UserAccountPage>()));
            }
            return(Redirect(UniquePageHelper.GetUrl <RegisterPage>()));
        }
示例#8
0
        public async Task <LoginResult> AuthenticateUser(LoginModel loginModel)
        {
            if (string.IsNullOrWhiteSpace(loginModel.ReturnUrl))
            {
                loginModel.ReturnUrl = null;
            }
            string message = null;

            var user = _userLookup.GetUserByEmail(loginModel.Email);

            if (user == null)
            {
                return new LoginResult {
                           Success = false, Message = "Incorrect email address"
                }
            }
            ;
            if (_passwordManagementService.ValidateUser(user, loginModel.Password) && user.IsActive)
            {
                var guid = CurrentRequestData.UserGuid;

                await _authorisationService.SetAuthCookie(user, loginModel.RememberMe);

                CurrentRequestData.CurrentUser = user;
                EventContext.Instance.Publish <IOnUserLoggedIn, UserLoggedInEventArgs>(
                    new UserLoggedInEventArgs(user, guid));
                return(user.IsAdmin
                    ? new LoginResult {
                    Success = true, RedirectUrl = loginModel.ReturnUrl ?? "~/admin"
                }
                    : new LoginResult {
                    Success = true, RedirectUrl = loginModel.ReturnUrl ?? "~/"
                });
            }
            return(new LoginResult {
                Success = false, Message = "Incorrect email or password."
            });
        }
    }