コード例 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                model.UserName = "******" + (Membership.GetAllUsers().Count + 1);
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                BibliotecaDataContext db= new BibliotecaDataContext();
                if (createStatus == MembershipCreateStatus.Success)
                {
                    Session["userid"]=(from i in db.aspnet_Users where i.UserName==model.UserName select i).ToArray()[0].UserId;
                    Roles.AddUserToRole(model.UserName,"Miembro");
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    linq_sqlDataContext db = new linq_sqlDataContext();
                    Usuario U = new Usuario { IdUsuario = System.Guid.NewGuid(), ApellidoPat = "", ApellidoMat = "", Nombre = "", Email = model.Email, Contrasena = model.Password, Avatar = "", Intereses = "", Karma = 0, NickName = "", Ubicacion = "" };

                    db.Usuario.InsertOnSubmit(U);
                    db.SubmitChanges();
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }