CreateUser() public static method

public static CreateUser ( string username, string password ) : System.Web.Security.MembershipUser
username string
password string
return System.Web.Security.MembershipUser
コード例 #1
0
 public ActionResult AddEmployee(AddEmployeeDetails model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     if (_employeeService.EmployeeExist(model.BankId, model.EmployeeCode ?? 0))
     {
         ModelState.AddModelError("Employee","The employee code is already in use.");
         return View(model);
     }
     if (_userManager.DoseUserExist(model.Username))
     {
         ModelState.AddModelError("User","The username is already taken.");
         return View(model);
     }
     MembershipCreateStatus status;
     Membership.CreateUser(model.Username, model.Password, model.Email, model.Question, model.Answer, true, out status);
     if (!ModelState.IsValid || status != MembershipCreateStatus.Success)
     {
         return View(model);
     }
     Roles.AddUserToRole(model.Username, "Banker");
     _employeeService.AddEmployee(model.BankId,new EmployeeBO
     {
         Code = model.EmployeeCode ?? 0,
         GivenName = model.GivenName,
         FamilyName = model.FamilyName,
         Phone = model.Phone,
         Email = model.Email,
         Username = model.Username
     });
     return RedirectToAction("BankEmployeeList", new { bankId = model.BankId });
 }
コード例 #2
0
 /// <summary>
 /// Creates new user
 /// <returns>If user was created</returns>
 /// </summary>
 private bool CreateUser()
 {
     try
     {
         Membership.CreateUser(TextBoxUserName.Text, TextBoxPassword.Text, Ticket.Email);
         UserName = TextBoxUserName.Text;
         Profile = EPiServerProfile.Get(UserName);
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
コード例 #3
0
ファイル: UserRepository.cs プロジェクト: thokozanik/clires
        /// <summary>
        /// The create app user with membership.
        /// </summary>
        /// <param name="appUser">
        /// The app user.
        /// </param>
        /// <param name="registeringUser">
        /// The registering user.
        /// </param>
        /// <param name="contact">
        /// The contact.
        /// </param>
        public void CreateAppUserWithMembership(IAppUser appUser, IRegistringUser registeringUser, IContact contact)
        {
            var memUser = MsMembership.CreateUser(registeringUser.UserName, registeringUser.Password, registeringUser.Email);
            var appuser = appUser.ToEntity();

            if (memUser.ProviderUserKey != null)
            {
                var user = GetUser(Guid.Parse(memUser.ProviderUserKey.ToString()));
                user.AppUsers.Add(appuser);
                Roles.AddUserToRole(registeringUser.UserName, registeringUser.Role);
                AddContact(contact);
                contact.AppUsers.Add(appuser);
                Commit();
            }
        }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                return;
            }

            string userName = Request["userName"];
            string userPass = Request["password"];
            string email    = Request["email"];
            string question = Request["question"];
            string answer   = Request["answer"];

            if (IsAnyEmpty(userName, userPass, email, question, answer))
            {
                ReportError("All fields must be filled");
            }
            else
            {
                MembershipCreateStatus status;
                /*MembershipUser membershipUser =*/
                UserManager.CreateUser(userName, userPass, email, question, answer, true, out status);
                if (status == MembershipCreateStatus.Success)
                {
                    if (!Roles.RoleExists(UsersRoleName))
                    {
                        Roles.CreateRole(UsersRoleName);
                    }

                    Roles.AddUserToRole(userName, UsersRoleName);
                    FormsAuthentication.SetAuthCookie(userName, false);
                    Response.Redirect(FormsAuthentication.LoginUrl);
                }
                else
                {
                    ReportError(status.ToString());
                }
            }
        }
コード例 #5
0
        private const string UsersRoleName = "users"; // NOTE: Извлечь эту инфу из конфига

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                return;
            }

            var registerVm = new RegisterVm();

            if (!TryUpdateModel(registerVm, new FormValueProvider(ModelBindingExecutionContext)))
            {
                return;
            }

            if (registerVm.Password != registerVm.ConfirmPassword)
            {
                ModelState.AddModelError(string.Empty, "Пароли не совпадают");
            }
            else
            {
                MembershipCreateStatus status;
                var membershipUser =
                    UserManager.CreateUser(
                        registerVm.Username, registerVm.Password, registerVm.Email, null, null, true, out status);
                if (status == MembershipCreateStatus.Success && membershipUser != null && ModelState.IsValid)
                {
                    Roles.AddUserToRole(membershipUser.UserName, UsersRoleName);
                    FormsAuthentication.SetAuthCookie(membershipUser.UserName, false);
                    Response.Redirect("~/Default.aspx");
                }
                else
                {
                    ModelState.AddModelError(string.Empty,
                                             string.Format("Создание пользователя завершилось неудачей. Возможная причина: {0}", status));
                }
            }
        }