Exemplo n.º 1
0
        public ActionResult Register(CreateAccountViewModel viewModel)
        {
            var validRes = ValidateRegistration(viewModel.Email, viewModel.Password, viewModel.ConfirmPassword, viewModel.Name);

            if (!validRes.IsValid)
            {
                TempData[RegistrationValidationSummaryKey] = validRes.ValidationSummary;
                return(this.RedirectLocal("~/Login"));
            }

            var user = _teeyootMembershipService.CreateUser(viewModel.Email, viewModel.Password, viewModel.Name, viewModel.Phone);

            if (user == null)
            {
                return(this.RedirectLocal("~/Login"));
            }

            _teeyootUserService.SendWelcomeEmail(user);

            _authenticationService.SignIn(user, false);

            return(string.IsNullOrEmpty(viewModel.ReturnUrl)
                ? Redirect("~/")
                : this.RedirectLocal(viewModel.ReturnUrl));
        }
Exemplo n.º 2
0
        public QuickLogOnResponse LogOn(QuickLogOnRequest request)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();

            if (currentUser != null)
            {
                _authenticationService.SignOut();
            }

            var lowerEmail = request.Email.ToLowerInvariant();

            var user = _orchardServices.ContentManager.Query <UserPart, UserPartRecord>()
                       .Where(u => u.NormalizedUserName == lowerEmail)
                       .List()
                       .FirstOrDefault();

            if (user == null)
            {
                user = _teeyootMembershipService.CreateUser(lowerEmail, Guid.NewGuid().ToString(), request.Email, null).As <UserPart>();
                if (user == null)
                {
                    return(new QuickLogOnResponse
                    {
                        User = null,
                        Error = T("User can not be created to assign to Quick LogOn credentials")
                    });
                }
                _teeyootUserService.SendWelcomeEmail(user);
            }

            _authenticationService.SignIn(user, request.RememberMe);

            return(new QuickLogOnResponse {
                User = user, ReturnUrl = request.ReturnUrl
            });
        }