Пример #1
0
 public static void DeleteUserInfo(UserInfo ui)
 {
     using (ISession session = sessions.OpenSession())
     using (ITransaction tx = session.BeginTransaction())
     {
         session.Delete(ui);
         tx.Commit();
     }
 }
Пример #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);
 }
Пример #3
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();
 }