Пример #1
0
 public Result RegisterHostUser(string userName, string name, string password, string email)
 {
     Result result = new Result();
     Account hostAccount = new Account(AccountType.Host,userName, password, name, email);
     bool usernameUnique = _userRepository.IsUsernameUnique(hostAccount.Username);
     MembershipCreateStatus createStatus;
     if (usernameUnique)
     {
         hostAccount = _userRepository.InsertAdminUser(hostAccount);
         createStatus = MembershipCreateStatus.Success;
     }
     else
     {
         createStatus = MembershipCreateStatus.DuplicateUserName;
     }
     if (createStatus == MembershipCreateStatus.Success)
     {
         _authenticationService.SignIn(hostAccount);
         result.Successful = true;
     }
     else
     {
         result.Errors.Add("", AccountValidation.ErrorCodeToString(createStatus));
     }
     return result;
 }
Пример #2
0
        public void SignIn(Account account)
        {
            if (account == null) throw new ArgumentException("Value cannot be null.", "account");

            DateTime ticketIssueTime = DateTime.Now;
            DateTime ticketExpiryTime = ticketIssueTime.AddMinutes(_configuration.AuthenticationExipryMinutes);
            string userData = string.Format("{0}|{1}", account.AccountId, account.AccountType);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, account.Name, ticketIssueTime, ticketExpiryTime, false, userData);
            string encryptedTicket = FormsAuthentication.Encrypt(ticket);
            HttpCookie authCookie = new HttpCookie(_configuration.AuthenticatedUserCookieName, encryptedTicket);
            HttpContext.Current.Response.Cookies.Add(authCookie);
        }
Пример #3
0
 public Account InsertAdminUser(Account account)
 {
     var connection = Database.OpenConnection(_configuration.GiftmeConnectionString);
     return connection.Account.Insert(account);
 }