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};
        }
Beispiel #2
0
        public QuickLogOnResponse LogOn(QuickLogOnRequest request)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            if (currentUser != null) _authenticationService.SignOut();

            var lowerEmail = request.Email == null ? "" : request.Email.ToLowerInvariant();

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

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

            if (user == null)
            {
                user = _membershipService.CreateUser(new CreateUserParams(lowerEmail, Guid.NewGuid().ToString(), lowerEmail, null, null, true)) as UserPart;
                if (user == null)
                {
                    return new QuickLogOnResponse { User = null, Error = T("User can not be created to assign to Quick LogOn credentials")};
                }
            }

            if (user.RegistrationStatus != UserStatus.Approved)
            {
                return new QuickLogOnResponse { User = null, Error = T("User was disabled by site administrator"), ReturnUrl = request.ReturnUrl };
            }

            _authenticationService.SignIn(user, request.RememberMe);

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