Esempio n. 1
0
 public ActionResult Create(RegisterModel model, FormCollection form)
 {
     if (ModelState.IsValid) {
         WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
         Roles.AddUserToRole(model.UserName, form["role"]);
         return RedirectToAction("Index");
     }
     return View(model);
 }
Esempio n. 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName,
                                                        model.Password,
                                                        propertyValues: new
                                                        {
                                                            Adress = model.Adress,
                                                            Town = model.Town,
                                                            Province = model.Province,
                                                            Country = model.Country,
                                                            FirstName = model.FirstName,
                                                            LastName = model.LastName,
                                                            EmailAdress = model.EmailAdress,
                                                            PhoneNumber = model.PhoneNumber,
                                                            PostalCode = model.PostalCode
                                                        });
                    WebSecurity.Login(model.UserName, model.Password);

                    if (Roles.RoleExists("User"))
                        Roles.AddUserToRole(model.UserName, "User");

                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 4
0
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid) {
         try {
             WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
             WebSecurity.Login(model.UserName, model.Password);
             Roles.AddUserToRole(model.UserName, "Client");
             return RedirectToAction("Index", "Books");
         } catch (MembershipCreateUserException e) {
             ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
         }
     }
     return View(model);
 }
        public ActionResult RegisterPost(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user with details provided
                try
                {
                    //create an array of bytes we will use to store the encrypted password
                   // Byte[] hashedBytes = EncryptPassword(model.Password);
                    string tmppwd = Crypto.HashPassword(model.Password);
                    WebSecurity.CreateUserAndAccount(model.Email, tmppwd);
                    User user = db.User.Where(u => u.Email == model.Email).FirstOrDefault();

                    //set hashed password
                    if (SetSecurityLevel(model.Email) == "")
                   {
                       ModelState.AddModelError("", "You must be a student from the following institutions: Conestoga College, Wilfred Laurier University , University Of Waterloo");
                       return View(model);
                    }
                   else if(SetSecurityLevel(model.Email) != "admin")
                   {
                       user.Securitylevel = "general";
                   }
                   else
                   {
                       user.Securitylevel = "admin";
                   }
                    user.pword = tmppwd;
                    db.SaveChanges();

                    var userId = WebSecurity.GetUserId(User.Identity.Name);                     // AUDIT
                    var userID = user.UserID;
                    //audit information
                   AuditController.AuditEntry(userId, userID, AuditController.ADD_USER);

                   WebSecurity.Login(model.Email, tmppwd);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }