ErrorCodeToString() public static méthode

public static ErrorCodeToString ( MembershipCreateStatus, createStatus ) : string
createStatus MembershipCreateStatus,
Résultat string
Exemple #1
0
        public Result RegisterHostUser(string userName, string name, string password, string email)
        {
            Result  result         = new Result();
            Account hostAccount    = new Account(AccountType.Host, userName, password, name, email);
            bool    usernameUnique = _userRepository.IsUsernameUnique(hostAccount.Username);
            MembershipCreateStatus createStatus;

            if (usernameUnique)
            {
                hostAccount  = _userRepository.InsertAdminUser(hostAccount);
                createStatus = MembershipCreateStatus.Success;
            }
            else
            {
                createStatus = MembershipCreateStatus.DuplicateUserName;
            }
            if (createStatus == MembershipCreateStatus.Success)
            {
                _authenticationService.SignIn(hostAccount);
                result.Successful = true;
            }
            else
            {
                result.Errors.Add("", AccountValidation.ErrorCodeToString(createStatus));
            }
            return(result);
        }
        public JsonResult ExistUsername(string username)
        {
            var member = _memberManager.MakeInstance();

            member.Username = username;
            var status = _memberService.Validate(member);
            var data   = new AjaxMessage();

            if (status == MembershipCreateStatus.Success)
            {
                data.Message = "username is avaiable";
                data.Success = true;
            }
            else
            {
                data.Message = AccountValidation.ErrorCodeToString(status);
                data.Success = false;
            }

            var result = new JsonResult();

            result.Data = data;
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(result);
        }
        public ActionResult Register(RegisterModel registerModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var bcryptHashed = BCrypt.HashPassword(registerModel.Password, BCrypt.GenerateSalt(10));

            var createStatus = AccountService.CreateUser(
                registerModel.Username,
                bcryptHashed,
                registerModel.Email
                );

            if (createStatus == AccountService.AccountCreateStatus.Success)
            {
                // AuthenticationService.SignIn(registerModel.Username, false /* createPersistentCookie */);
                // return RedirectToAction("Login", "Account", new { registered = "true" });

                return(RedirectToAction("login", "account", new { message = "registersuccess" }));
            }
            else
            {
                ViewBag.Notification = string.Format("showError('{0}');", AccountValidation.ErrorCodeToString(createStatus));
                ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
            }
            return(View(registerModel));
        }
        public ActionResult CreateUser(RegisterModel model, string[] roles)
        {
            if (ModelState.IsValid)
            {
                string[] reserves = App.Settings.ReservedUserNames;
                if (reserves.Contains(model.UserName.ToLower()))
                {
                    ModelState.AddModelError("", string.Format(Resources.Validations.UserName_Reserved, "\"" + model.UserName + "\""));
                }
                else
                {
                    var context = DependencyResolver.Current.GetService <IDataContext>();
                    var status  = context.Users.CreateUser(model.UserName, model.Password, model.Email);
                    if (status != UserCreateStatus.Success)
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(status));
                    }
                    else
                    {
                        if (roles != null && roles.Length > 0)
                        {
                            var rl = roles.ToList();
                            rl.Remove("guests");
                            var user = App.Get().Users[model.UserName];
                            user.AddToRoles(roles);
                        }

                        return(Redirect("~/host/users"));
                    }
                }
            }
            return(View());
        }
Exemple #5
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Use a transaction
                //using (System.Transactions.TransactionScope trans = new System.Transactions.TransactionScope())
                //{
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    // Register user in the SimpleList database
                    var userRepository = new UserRepository();
                    var user           = new User {
                        Name = model.UserName, Password = model.Password, Email = model.Email
                    };
                    userRepository.AddUser(user);
                    //trans.Complete();

                    // Sign the new user in, final step before closing the transaction
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
                //}
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #6
0
        public ActionResult Create(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = Guid.NewGuid();

                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email, userId);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    _context.Users.InsertOnSubmit(new User()
                    {
                        Id      = userId,
                        Credits = 0
                    });

                    _context.SubmitChanges();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            return(View(model));
        }
Exemple #7
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);

                    return(RedirectToAction("index", "Content", new { area = "UI" }));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form

            ViewBag.Class          = "register";
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
        public ActionResult EditUser(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.Email, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    MembershipUser user = Membership.GetUser(model.Email);
                    //AreaDAC.AddAreaRelation(user.ProviderUserKey, areaID);
                    //FormsService.SignIn(model.UserName, false /* createPersistentCookie */);

                    UserDTO loggedInUser = UserDAC.RestoreByName(Membership.GetUser().UserName);

                    UserDTO newUser = new UserDTO(null, model.Email, loggedInUser.Company_ID, model.Email, loggedInUser.DefaultAreaID);
                    UserDAC.Store(newUser);
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    applicationBus.Send(new UserLoggedInMessage {
                        Username = model.UserName
                    });

                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #10
0
 public ActionResult CreateUser(RegisterModel user)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var status = userAdminService.CreateUser(user.UserName, user.Password, user.Email, user.Role);
             if (status != MembershipCreateStatus.Success)
             {
                 ViewBag.Message = string.Format("<p class='warning'>{0}<p>", AccountValidation.ErrorCodeToString(status));
                 return(View("User"));
             }
             TempData["Message"] = string.Format("<p class='note'>User '{0}' successfully created.<p>", user.UserName);
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
             ViewBag.Message = string.Format("<p class='warning'>There was a problem creating this user. {0}<p>", ex.Message);
             return(View("User"));
         }
     }
     ViewBag.Message = "<p class='warning'>Unable to create user.<p>";
     return(View("User"));
 }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                string[] reserves = App.Settings.ReservedUserNames;
                //new string[] { "host", "home", "index", "default", "{blog}", "sites", "{site}" };
                if (reserves.Contains(model.UserName.ToLower()))
                {
                    ModelState.AddModelError("", string.Format(Resources.Validations.reCapticha_UnvalidKey, "\"" + model.UserName + "\""));
                }
                else
                {
                    var context = DependencyResolver.Current.GetService <IDataContext>();
                    var status  = context.Users.CreateUser(model.UserName, model.Password, model.Email);
                    if (status != UserCreateStatus.Success)
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(status));
                    }
                    else
                    {
                        //if (App.Get().User.IsInRole(
                        var user = App.Get().Users[model.UserName];
                        if (!user.IsInRole("administartors"))
                        {
                            App.Get().Roles.AddUserToRole(model.UserName, "administrators");
                        }
                        user.DefaultWeb = "home";
                        user.Save();

                        DnaConfig.UpdateWebConfig("configuration/appSettings/add[@key=\"Administrator\"]", "value", model.UserName);
                    }
                }
            }
            return(PartialView(model));
        }
        public ActionResult SubscribeRemote(string id, RemoteSubscriptionViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                MembershipUser         user = MembershipService.CreateUser(model.Username, model.Password, model.Email, model.Question, model.Answer, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    IProduct productResult = (from a in Chargify.GetProductList().Values
                                              where a.Handle == id
                                              select a).SingleOrDefault();

                    string hostedPageUrl = Chargify.URL;
                    hostedPageUrl += "h/" + productResult.ID + "/subscriptions/new?reference=" + user.ProviderUserKey.ToString() + "&email=" + model.Email;
                    return(Redirect(hostedPageUrl));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }

                return(RedirectToAction("SubscribeRemote", new { id = id }));
            }
            else
            {
                return(RedirectToAction("SubscribeRemote", new { id = id }));
            }
        }
Exemple #13
0
        public virtual ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var createStatus = MembershipService.CreateUser(new CreateUserMembershipParams
                {
                    Email    = model.Email,
                    Password = model.Password,
                    FullName = model.FullName
                });

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.Email, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #14
0
        public ActionResult NewUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Profile == UserProfile.None || model.Profile > SessionData.UserProfile)
                {
                    ModelState.AddModelError("Profile", "No puede crearse un usuario con ese perfil.");
                }
                else
                {
                    string password = model.UserName;
                    MembershipCreateStatus createStatus = UsersController.CreateUser(model.UserName, model.UserDescription,
                                                                                     password, model.Email, model.Profile, -1);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        ViewBag.Message = "Usuario Creado";
                        return(Users());
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, AccountValidation.ErrorCodeToString(createStatus));
                    }
                }
            }

            ViewBag.PasswordLength = UsersController.GetMinRequiredPasswordLength();

            return(View("User", model));
        }
Exemple #15
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // 尝试注册用户
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.FullName, model.DeptId);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    //return RedirectToAction("Index", "Home");
                    ViewBag.PasswordLength = MembershipService.MinPasswordLength;
                    //Response.Write("<script>alert('注册用户成功');</script>");
                    //Response.Write("<script>window.location.href='" + Url.Action("Register") + "';</script>");
                    //return PartialView(model);
                    return(RedirectToAction("RegisterSucess", "Account"));
                    //return Json(new { Success = false, Message = "创建帐户失败:用户名或密码在错误!" },JsonRequestBehavior.AllowGet);
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
            //return Json(new { Success = false, Message = "创建帐户失败:提交的数据存在错误!" });
        }
Exemple #16
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                //检查用户是否存在
                bool isExist = MembershipService.GetUser(model.UserName);
                if (isExist)
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(MembershipCreateStatus.DuplicateUserName));

                    return(View());
                }
                // 尝试注册用户
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password);

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

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #17
0
        public ActionResult Register(RegisterModel model)
        {
            //validate input
            if (string.IsNullOrEmpty(model.UserName))
            {
                ModelState.AddModelError("username", "Username is required");
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("password", "The password and confirmation password do not match");
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

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

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #18
0
        public ActionResult Staff(itmmAdminStaff model, string type)
        {
            if (ModelState.IsValid)
            {
                AccountMembershipService MembershipService = new AccountMembershipService();
                MembershipCreateStatus   createStatus      = MembershipService.CreateUser(model.uname, model.password, model.eadd);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.uname, "Staff");

                    Laboratory_Staff a = new Laboratory_Staff();
                    a.FirstName     = model.fname;
                    a.LastName      = model.lname;
                    a.IdNumber      = model.cnum;
                    a.CourseAndYear = model.course;
                    a.EmailAddress  = model.eadd;
                    a.Type          = type;
                    a.UserName      = model.uname;
                    //for LabId
                    var c = (from y in con.Laboratories
                             where y.UserName == User.Identity.Name
                             select y.LaboratoryId).FirstOrDefault();
                    a.LaboratoryId = c;
                    con.AddToLaboratory_Staff(a);
                    con.SaveChanges();

                    return(RedirectToAction("Staff", "Head"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return(View(model));
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    /* //th20101124 ให้ไปใส่ Detail อื่น ๆ ต่อ
                     * FormsService.SignIn(model.UserName, false);
                     * return RedirectToAction("Index", "Home");
                     */
                    var    UserList = Membership.FindUsersByName(model.UserName);
                    string userid   = "";
                    foreach (MembershipUser user in UserList)
                    {
                        userid = user.ProviderUserKey.ToString();
                        break;
                    }
                    return(RedirectToAction("Details", "UserAdministration", new { area = "UserAdministration", id = userid }));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #20
0
        public ActionResult Register(UserViewModel model)
        {
            MembershipCreateStatus createStatus;

            if (ModelState.IsValid)
            {
                try{
                    // try to register user
                    var newUser = _bl.Authentication.CreateUser();
                    model.ApplyChanges(newUser, ModelState);
                    if (ModelState.IsValid)
                    {
                        _bl.SaveChanges();

                        createStatus = MembershipCreateStatus.Success;
                        _bl.Authentication.SignIn(model.Benutzername, false /* createPersistentCookie */);
                        return(View("RegisterSuccess", model));
                    }
                }
                catch (Exception e)
                {
                    String stack = e.StackTrace;
                    createStatus = MembershipCreateStatus.ProviderError;
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            ViewData["PasswordLength"] = _bl.Authentication.MinPasswordLength;
            return(View(model));
        }
Exemple #21
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    //Encode the username in base64
                    byte[]     toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(model.UserName);
                    HttpCookie authCookie      = new HttpCookie("username", System.Convert.ToBase64String(toEncodeAsBytes));
                    authCookie.HttpOnly = true;
                    authCookie.Secure   = true;
                    HttpContext.Response.Cookies.Add(authCookie);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View(model));
        }
        public void ErrorCodeToStringTest()
        {
            Random random = new Random();
            string actual = AccountValidation.ErrorCodeToString((MembershipCreateStatus)random.Next(11));

            Assert.IsFalse(string.IsNullOrWhiteSpace(actual));
        }
Exemple #23
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.txtCode == StringCipher.Decrypt(model.hdnCode.ToString(), model.Email.ToString() + "A123b789"))
                {
                    // Attempt to register the user
                    MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

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

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
        public virtual ActionResult CreateUser(SecurityManagementUserViewModel user)
        {
            var repository = Security.Repository as TicketDesk.Domain.Repositories.SqlSecurityRepository;
            var membership = repository.MembershipSource;

            if (ModelState.IsValid)
            {
                MembershipCreateStatus createStatus;
                var u = membership.CreateUser(user.UserName, user.Password, user.Email, null, null, true, null, out createStatus);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    u.Comment = user.DisplayName;
                    membership.UpdateUser(u);
                    if (Security.IsTdAdmin(user.UserName) != user.IsAdmin)
                    {
                        if (user.IsAdmin)
                        {
                            Security.AddUserToTdAdmin(user.UserName);
                        }
                        else
                        {
                            Security.RemoveUserFromTdAdmin(user.UserName);
                        }
                    }
                    if (Security.IsTdStaff(user.UserName) != user.IsStaff)
                    {
                        if (user.IsStaff)
                        {
                            Security.AddUserToTdStaff(user.UserName);
                        }
                        else
                        {
                            Security.RemoveUserFromTdStaff(user.UserName);
                        }
                    }
                    if (Security.IsTdSubmitter(user.UserName) != user.IsSubmitter)
                    {
                        if (user.IsSubmitter)
                        {
                            Security.AddUserToTdSubmitter(user.UserName);
                        }
                        else
                        {
                            Security.RemoveUserFromTdSubmitter(user.UserName);
                        }
                    }
                    return(RedirectToAction(MVC.Admin.SecurityManagement.UsersList()));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));

                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Exemple #25
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    TinyLibraryServiceClient svcClient = new TinyLibraryServiceClient();
                    bool ret = svcClient.AddReader(new ReaderData
                    {
                        Id       = Guid.NewGuid(),
                        Name     = model.Name,
                        UserName = model.UserName
                    });
                    svcClient.Close();
                    if (ret)
                    {
                        FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #26
0
        public ActionResult Add(RegisterEmployeeModel model)
        {
            try
            {
                //Explicitly Validate Model for UserRole
                if (model.UserRole != EmployeeUserRole.Admin && model.UserRole != EmployeeUserRole.Employee)
                {
                    ModelState.AddModelError("createstatus", "An Employee Needs to be assigned one of the Roles");
                }
                if (ModelState.IsValid)
                {
                    // Attempt to register the employee
                    MembershipCreateStatus createStatus;
                    var restaurantuser = MembershipService.CreateUser(
                        new RestaurantUser(0, model.EmployeeName, Guid.NewGuid())
                    {
                        EmailId      = model.Email,
                        MobileNumber = UInt64.Parse(model.MobileNumber ?? "0"),
                        Address      = model.Address,
                        Password     = model.Password,
                        UserRole     = (UserBase.RestaurantUserRole)((int)model.UserRole)
                    }
                        , out createStatus, model.SecretQuestion, model.SecretAnswer);

                    if (createStatus == MembershipCreateStatus.Success && restaurantuser != null)
                    {
                        TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                        {
                            Message = String.Format("{0} was successfully Added as a new {1}", model.EmployeeName, model.UserRole),
                            Result  = true,
                            State   = ActionResultNotification.MessageState.Information
                        };
                        return(RedirectToAction("Index"));
                    }
                    ModelState.AddModelError("createstatus", AccountValidation.ErrorCodeToString(createStatus));
                }
                // If we got this far, something failed, redisplay form
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = ModelState.ContainsKey("createstatus") ? ModelState["createstatus"].Errors[0].ErrorMessage : "There was an Error registering you as our Guest User, please try again",
                    Result  = false,
                    State   = ActionResultNotification.MessageState.Error
                };
                ViewBag.PasswordLength = MembershipService.MinPasswordLength;
                return(View(model));
            }
            catch (Exception e)
            {
                TempData[TempDataStringResuorce.ActionResultNotification] = new ActionResultNotification
                {
                    Message = e.Message,
                    Result  = false,
                    State   = ActionResultNotification.MessageState.Error
                };
                return(View(model));
            }
        }
Exemple #27
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    StreamReader objLector;
                    string       HTML = "";

                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);

                    // Send welcome e-mail using local host.
                    SmtpClient smtpClient = new SmtpClient();
                    smtpClient.UseDefaultCredentials = true;

                    objLector = System.IO.File.OpenText(Server.MapPath("~/Content/mail/Welcome.html"));
                    HTML      = objLector.ReadToEnd();
                    objLector.Close();

                    HTML = HTML.Replace("@user", model.UserName);

                    string      to      = model.Email;
                    string      from    = "*****@*****.**";
                    MailMessage message = new MailMessage(from, to);
                    message.Subject    = "Welcome to AriasWall";
                    message.Body       = HTML;
                    message.IsBodyHtml = true;
                    //SMTP config.
                    smtpClient.Host = "localhost";
                    smtpClient.Port = 25;

                    try
                    {
                        smtpClient.Send(message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
                                          ex.ToString());

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #28
0
        public ActionResult CreatePerson(int id, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            ModelState.Clear();

            var person = personEditModel.Person;

            var user = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());

            person.User = user;

            SeminarPerson seminarPerson = null;

            person = SetPerson(personEditModel, seminarPerson, ModelState, person, profilepic);

            ModelState.Remove("Person.User");

            if (ModelState.IsValid)
            {
                // try to create the user
                var createStatus = _membershipService.CreateUser(personEditModel.UserName
                                                                 , Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10)
                                                                 , personEditModel.Email);

                // retrieve the user to assign
                var createdUser = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());
                person.User = createdUser;

                // save only if user creation was successful
                if (createStatus == MembershipCreateStatus.Success)
                {
                    person.AddSite(SiteService.LoadSite(Site));

                    // we're good save the person object
                    _personRepository.EnsurePersistent(person);
                    Message = string.Format(Messages.Saved, "Person");

                    if (person.OriginalPicture != null)
                    {
                        return(this.RedirectToAction <PersonController>(a => a.UpdateProfilePicture(person.Id, null, false)));
                    }

                    return(this.RedirectToAction <PersonController>(a => a.AdminEdit(person.User.Id, null, true)));
                }

                ModelState.AddModelError("Create User", AccountValidation.ErrorCodeToString(createStatus));
            }

            var viewModel = PersonViewModel.Create(Repository, _firmService, Site, null, person, personEditModel.Email);

            viewModel.Addresses = personEditModel.Addresses;
            viewModel.UserName  = personEditModel.UserName;
            return(View(viewModel));
        }
        public ActionResult SignUp(SignUpClientModel model, string returnUrl)
        {
            if (!_repository.RuleAnswers.IsUserEligible(Session.SessionID))
            {
                return(RedirectToAction("Index", "Rules"));
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    var profile = UserProfile.GetUserProfile(model.UserName);
                    profile.FirstName        = model.FirstName;
                    profile.MiddleInitial    = model.MiddleInitial;
                    profile.LastName         = model.LastName;
                    profile.RegistrationDate = DateTime.Now;
                    if (Session["County"] != null)
                    {
                        var countyId = int.Parse(Session["County"].ToString());
                        profile.County = _repository.Counties.First(x => x.Id == countyId).CountyName;
                    }

                    profile.Save();

                    Roles.AddUserToRole(model.UserName, UserRoles.BasicUser);
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);

                    _emailService.SendEmailTo(model.Email, new ClientRegistrationEmail(model.UserName));

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Exemple #30
0
        public virtual ActionResult RegisterWithOrganization(OrganizationRegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                MembershipCreateStatus createStatus;

                // Attempt to register the user
                try
                {
                    createStatus = MembershipService.CreateUser(new CreateUserMembershipParams
                    {
                        Email    = model.Email,
                        Password = model.Password,
                        OrganizationRegistrationToken = model.RegistrationToken,
                        FullName = model.FullName
                    });

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsService.SignIn(model.Email, false /* createPersistentCookie */);
                        return(RedirectToAction(MVC.Home.Index()));
                    }
                    else
                    {
                        ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    }
                }
                catch (InvalidEmailDomainForOrganizationException)
                {
                    ModelState.AddModelError("", "The entered email address is not allowed for this organization");
                }
            }

            // If we got this far, something failed, redisplay form

            // Retrieve the organization based on the token
            var org = _serviceFactory.GetService <OrganizationByRegistrationTokenQuery>()
                      .Execute(new OrganizationByRegistrationTokenQueryParams {
                RegistrationToken = model.RegistrationToken
            });

            if (org.EmailDomains.Count > 0)
            {
                model.RestrictedEmailDomain = org.EmailDomains.First().Domain;
            }

            model.MinPasswordLength = Membership.MinRequiredPasswordLength;
            return(View(model));
        }