Exemple #1
0
 public async Task <ActionResult> Login(LoginModel model)
 {
     try
     {
         IdentityRepository.RemoveUsers(new TimeSpan(0, 30, 0));
         var password = $"{Random.Instance.Next(100000, 1000000)}";
         IdentityRepository.CreateUser(
             new AccountModel {
             AccountName = model.Account, IsActivate = true, Role = ERoles.User
         }, password);
         if (WebSecurity.Login(model.Account, password))
         {
             SystemMessagesRepository.Send($"Пользователь {model.Account} вошел в чат.");
             var result = TempData["ReturnUrl"] != null
                 ? (ActionResult)Redirect((string)TempData["ReturnUrl"])
                 : RedirectToAction("Index", "Home");
             return(await GetAsyncResult(result));
         }
     }
     catch (Exception exception)
     {
         ModelState.AddModelError("", exception.Message);
     }
     return(await GeneratorActionResult("~/Accounts/Login/action.cshtml", new LoginModel()));
 }
Exemple #2
0
        public void DeleteUser(string userName)
        {
            var roles = Roles.GetRolesForUser(userName);

            Roles.RemoveUserFromRoles(userName, roles);
            ((SimpleMembershipProvider)Membership.Provider).DeleteAccount(userName);
            ((SimpleMembershipProvider)Membership.Provider).DeleteUser(userName, true);
            SystemMessagesRepository.Send($"Пользователь {userName} покинул чат.");
        }