Exemple #1
0
        public ActionResult Enter(EnterModel model)
        {
            if (ModelState.IsValid)
            {
                if (lgHelper.ValidateUser(model.Login, model.Password))
                {
                    dbHelper.Configure();
                    CurrentUser = DbHelper.FindContacts(model.Login)[0].User;

                    var cookie = new HttpCookie("ID") {Value = model.Login, Expires = DateTime.Now.AddMonths(3)};
                    System.Web.HttpContext.Current.Response.SetCookie(cookie);
                    if (model.Login == "Admin")
                    {
                        CheckInputAdmin = true;
                    }
                    return Json(new { state = "success", parameters = new { url = Url.Action("Index", "Home") } });
                }
            }
            return Json(new {state = "error", parameters = new {message = ValidationStrings.IncorrectEnter}},
                        JsonRequestBehavior.AllowGet);
        }
Exemple #2
0
 public void UpdateBase()
 {
     dbHelper.Configure();
     dbHelper.CreateTables();
     var user = new User
     {
         Login = "******",
         Password = "******",
         Email = null,
         Salt = lgHelper.CreateSalt(),
         IsActivated = 1,
         CreateData = DateTime.Now,
         EmailKey = null
     };
     var info = new Info { FirstName = null, LastName = null, Age = null };
     var ui = new UserInfo { User = user, Info = info };
     user.PasswordSaltHash = lgHelper.CreatePasswordHash(user.Password, user.Salt);
     DbHelper.InsertUser(user);
     DbHelper.InsertInfo(info);
     DbHelper.InsertUserInfo(ui);
 }
Exemple #3
0
 public ActionResult Exit()
 {
     if (System.Web.HttpContext.Current.Request.Cookies["ID"] != null)
     {
         var cookie = new HttpCookie("ID")
                          {
                              Expires = DateTime.Now.AddDays(-1d)
                          };
         System.Web.HttpContext.Current.Response.SetCookie(cookie);
     }
     CurrentUser = null;
     if (CheckInputAdmin) CheckInputAdmin = false;
     return RedirectToAction("Index", "Home");
 }
Exemple #4
0
 public ActionResult Login(LoginModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (model.Password != model.ConfirmPassword)
             {
                 return Json(new {error_message = ValidationStrings.PasswordsMustMatch},
                             JsonRequestBehavior.AllowGet);
             }
             dbHelper.Configure();
             var findLogin =  DbHelper.FindContacts(model.Login);
             if (findLogin.Count != 0)
             {
                 return Json(new {error_message = ValidationStrings.LoginInDb},
                             JsonRequestBehavior.AllowGet);
             }
             var user = new User
                            {
                                Login = model.Login,
                                Password = model.Password,
                                Email = model.Email,
                                Salt = lgHelper.CreateSalt(),
                                IsActivated = 0,
                                CreateData = DateTime.Now,
                                EmailKey = lgHelper.GenerateKey()
                            };
             var info = new Info {FirstName = model.FirstName, LastName = model.LastName, Age = model.Age};
             var ui = new UserInfo {User = user, Info = info};
             user.PasswordSaltHash = lgHelper.CreatePasswordHash(user.Password, user.Salt);
             string activationLink = "http://localhost:2885/Users/Activate/" +
                                     user.Login + "/" + user.EmailKey;
             SendMail.SendEmail(activationLink, user.Email);
             DbHelper.InsertUser(user);
             DbHelper.InsertInfo(info);
             DbHelper.InsertUserInfo(ui);
             return Json(new {redirect = Url.Action("Welcome", "Home")});
         }
     }
     catch(Exception e)
     {
         ViewData["Error"] = e.Message;
     }
     return RenderAnswer();
 }
Exemple #5
0
 public static void UpdateUser(User user)
 {
     using (ISession session = sessions.OpenSession())
     using (ITransaction tx = session.BeginTransaction())
     {
         session.Update(user);
         tx.Commit();
     }
 }