Exemple #1
0
 public ActionResult IsUsernameFree([FromUri] string username)
 {
     using (var unoDb = new UnoDbContext())
     {
         var all = unoDb.Users.All(u => u.Username != username);
         return Json(new {response = all}, JsonRequestBehavior.AllowGet);
     }
 }
Exemple #2
0
 public ActionResult SignUp(RegisterViewModel register)
 {
     using (var unoDb = new UnoDbContext())
     {
         if (unoDb.Users.Any(u => u.Username == register.Username))
             return Error("There is exists user with the same username");
         unoDb.Users.Add(new User
         {
             //Email = register.Email,
             Password = Encrypt.SHA1(register.Password),
             Username = register.Username
         });
         unoDb.SaveChanges();
     }
     return LogIn(new LoginViewModel {Username = register.Username, Password = register.Password});
 }
Exemple #3
0
        public ActionResult LogIn(LoginViewModel login)
        {
            using (var unoDb = new UnoDbContext())
            {
                var user = unoDb.Users.SingleOrDefault(u => u.Username == login.Username);
                if (user == null)
                    return Error("No such user");// HttpNotFound("No such user"); // TODO: TEMP
                var hashedPasswordString = Encrypt.SHA1(login.Password);
                if (!user.Password.Equals(hashedPasswordString, StringComparison.OrdinalIgnoreCase))
                    return Error("Password wrong");

                var ticket = new FormsAuthenticationTicket(login.Username, true, (int)TimeSpan.FromDays(7).TotalMinutes);
                var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                Response.SetCookie(new HttpCookie("userid", encryptedTicket));
            }
            return RedirectToAction("Index", "Room");
        }