예제 #1
0
        public ActionResult Register(RegistrationModel info)
        {
            using (BusinessLogicLayer.ContextBLL ctx = new BusinessLogicLayer.ContextBLL())
            {
                BusinessLogicLayer.UserBLL user = ctx.FindUserByEMail(info.EMail);
                if (user != null)
                {
                    info.Message = $"The EMail Address '{info.EMail}' already exists in the database";
                    return(View(info));
                }
                user             = new UserBLL();
                user.DateOfBirth = info.DateOfBirth;
                user.EMail       = info.EMail;
                user.Salt        = System.Web.Helpers.Crypto.
                                   GenerateSalt(MagicConstants.SaltSize);
                user.Hash = System.Web.Helpers.Crypto.
                            HashPassword(info.Password + user.Salt);
                user.RoleID = 3;

                ctx.CreateUser(user);
                Session["AUTHUsername"] = user.EMail;
                Session["AUTHRoles"]    = user.RoleName;
                Session["AUTHTYPE"]     = "HASHED";
                return(RedirectToAction("Index"));
            }
        }
예제 #2
0
 public ActionResult Create(Models.CreateUser info)
 {
     try
     {
         //using (BusinessLogicLayer.ContextBLL ctx = new BusinessLogicLayer.ContextBLL())
         //{
         if (!ModelState.IsValid)
         {
             return(View(info));
         }
         using (BusinessLogicLayer.ContextBLL ctx = new BusinessLogicLayer.ContextBLL())
         {
             BusinessLogicLayer.UserBLL user = ctx.FindUserByUserName(info.UserName);
             //if (user != null)
             //{
             //    info.Message = $"The EMail Address '{info.Email}' already exists in the database";
             //    return View(info);
             //}
             user             = new UserBLL();
             user.FirstName   = info.FirstName;
             user.LastName    = info.LastName;
             user.UserName    = info.UserName;
             user.DateOfBirth = info.DateOfBirth;
             user.RoleID      = info.RoleID;
             user.SALT        = System.Web.Helpers.Crypto.
                                GenerateSalt(Constants.SaltSize);
             user.HASH = System.Web.Helpers.Crypto.
                         HashPassword(info.Password + user.SALT);
             user.Email = info.Email;
             ctx.CreateUser(user);
             Session["AUTHUserName"] = user.UserName;
             Session["AUTHRoles"]    = user.RoleName;
             Session["AUTHTYPE"]     = "HASHED";
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception Ex)
     {
         ViewBag.Exception = Ex;
         return(View("Error"));
     }
 }