Beispiel #1
0
        public ActionResult CreateAccountPost(AccountModel model)
        {
            model.Valid = ModelState.IsValid;
            if (model.Valid)
            {
                var factory = MvcApplication.SessionFactory;
                NhSession = factory.OpenSession();
                var existingAccount = NhSession.QueryOver<Identity>().Where(i => i.Email == model.Identity.Email && i.Registered).List();
                if (existingAccount.IsEmpty())
                {
                    using (var transaction = NhSession.BeginTransaction())
                    {
                        var identity = NhSession.Get<Identity>(model.Id);

                        identity.Name = model.Identity.Name;
                        identity.Email = model.Identity.Email;
                        identity.Salt = HashHelper.GenerateSaltValue();
                        identity.EncodedPassword = HashHelper.HashPassword(model.Password, identity.Salt);
                        identity.Registered = false;

                        NhSession.Save(identity);
                        transaction.Commit();
                    }
                }
                else
                {
                    ModelState.AddModelError("EmailTaken", "The emailaddress you entered already exists in our database");
                }
            }
            return PartialView("AccountPartial", model);
        }
Beispiel #2
0
        public ActionResult Login()
        {
            var model = new AccountModel() { Identified = HardIdentify() != null };

            if (model.Identified)
                return View("Error", new ErrorModel("Already logged in"));

            return View("Login", model);
        }
Beispiel #3
0
 public ActionResult Login(AccountModel model)
 {
     var account = RetrieveIdentity(model.Identity.Name);
     if (account != null && account.EncodedPassword == GetHash(model.Identity.Password))
     {
         GrantValidationCookie(0, account.Id);
         return RedirectToAction("index", "Gang", null);
     }
     else
     {
         return View("Error", new ErrorModel("Account name and or password combination is invalid"));
     }
 }
Beispiel #4
0
        public ActionResult CreateAccountPost(AccountModel model)
        {
            model.Valid = ModelState.IsValid;
            if (model.Valid)
            {
                using (var transaction = NhSession.BeginTransaction())
                {
                    var identity = NhSession.Get<Identity>(model.Id);

                    identity.Name = model.Identity.Name;
                    identity.Email = model.Identity.Email;
                    identity.EncodedPassword = GetHash(model.Identity.Password);
                    identity.Registered = false;

                    NhSession.Save(identity);
                    transaction.Commit();
                }
            }
            return PartialView("AccountPartial", model);
        }