示例#1
0
        public void CreateAccount(Account account)
        {
            if (account == null)
                throw new ArgumentNullException("account");

            _accountRepository.Insert(account);
        }
        public virtual void SignIn(Account account, bool createPersistentCookie)
        {
            var now = DateTime.UtcNow.ToLocalTime();

            var ticket = new FormsAuthenticationTicket(
                1 /*version*/,account.Email,
                now,
                now.Add(_expirationTimeSpan),
                createPersistentCookie,account.Email,
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            cookie.HttpOnly = true;
            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }
            cookie.Secure = FormsAuthentication.RequireSSL;
            cookie.Path = FormsAuthentication.FormsCookiePath;
            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            _httpContext.Response.Cookies.Add(cookie);
            _cachedAccount = account;
        }
 public AccountRegistrationRequest(Account account, string email,string password,PasswordFormat passwordFormat)
 {
     Account = account;
     Email = email;
     Password = password;
     PasswordFormat = passwordFormat;
 }
示例#4
0
        public ActionResult Register(RegisterModel model, string returnUrl, FormCollection form)
        {
            if (_workContext.CurrentAccount == null || _workContext.CurrentAccount.IsRegistered())
            {
                //Already registered customer. 
                _authenticationService.SignOut();
              
                //Save a new record
               // _workContext.CurrentAccount = _accountService.InsertGuestAccount();
            }

            var account = new Account(){
                  Birthdate = model.Birthdate,
                  Contact = model.Contact,
                Country= model.Country,
                  Email = model.Email,
                   Deleted = false,
                   Gender = model.Gender,
                   Language = model.Language,
                   CreatedOnUtc = DateTime.Now,
                   LastActivityDateUtc = DateTime.Now,
                   AccountGuid = Guid.NewGuid()

                   
            };

            
            if (ModelState.IsValid)
            {
                 
                   var registrationRequest = new AccountRegistrationRequest(account, model.Email, model.Password, PasswordFormat.Hashed);
               // _accountService.InsertGuestAccount
                var registrationResult = _accountRegistrationService.RegisterAccount(registrationRequest);
                if (registrationResult.Success)
                { _accountService.CreateAccount(account);
                  
                    _authenticationService.SignIn(account, true);
                    return RedirectToRoute("HomePage");
                }
                else
                {
                    foreach (var error in registrationResult.Errors)
                        ModelState.AddModelError("", error);
                }
            }
            return View(model);
        }
        public virtual Account GetAuthenticatedAccount()
        {
            if (_cachedAccount != null)
                return _cachedAccount;

            if (_httpContext == null ||
                _httpContext.Request == null ||
                !_httpContext.Request.IsAuthenticated ||
                !(_httpContext.User.Identity is FormsIdentity))
            {
                return null;
            }

            var formsIdentity = (FormsIdentity)_httpContext.User.Identity;
            var account = GetAuthenticatedCustomerFromTicket(formsIdentity.Ticket);
            if (account != null && account.Active && !account.Deleted && account.IsRegistered())
                _cachedAccount = account;
            return _cachedAccount;
        }
示例#6
0
        public void UpdateAccount(Account account)
        {
            if (account == null)
                throw new ArgumentNullException("account");

            _accountRepository.Update(account);
        }
示例#7
0
        public Account InsertGuestAccount()
        {
            var account = new Account()
            {
                AccountGuid = Guid.NewGuid(),
                Active = true,
                CreatedOnUtc = DateTime.UtcNow,
                LastActivityDateUtc = DateTime.UtcNow,
                Birthdate = DateTime.UtcNow,
            };

            //add to 'Guests' role
            var guestRole = GetAccountRoleBySystemName(SystemAccountRoleNames.Guests);
            if (guestRole == null)
                throw new Exception("'Guests' role could not be loaded");
            account.AccountRoles.Add(guestRole);
            _accountRepository.Insert(account);

            return account;
        }
 public virtual void SignOut()
 {
     _cachedAccount = null;
     FormsAuthentication.SignOut();
 }