public ActionResult Create(CreateAccountModel model,string returnUrl)
        {
            if (ModelState.IsValid && String.Equals(model.Password, model.ConfirmPassword))
            {
                Dictionary<string, string> errors= AccountHelper.CreatAccount(model);
                if (errors.Count ==0)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    returnUrl = String.IsNullOrEmpty(returnUrl) ? "/Account" : returnUrl;
                    return Redirect(returnUrl);
                }

                foreach (var err in errors)
                {
                    ModelState.AddModelError(string.Empty, err.Value);
                }
                return View(model);
            }

            return View(model);
        }
Пример #2
0
        public static Dictionary<string, string> CreatAccount(CreateAccountModel model)
        {
            Dictionary<string, string> accountCreationErrors = new Dictionary<string, string>();

            if (!Data.Accessors.UsersAccessor.UserExists(model.UserName))
            {
                Data.User dbUserModel = new Data.User();
                dbUserModel.CurrentMotorcycle = model.CurrentMotorcycle;
                dbUserModel.UserName = model.UserName;
                dbUserModel.AdminLevel = 1;
                dbUserModel.Salt = DateTime.Now.Ticks.ToString();
                byte[] salt = Encoding.UTF8.GetBytes(dbUserModel.Salt);

                dbUserModel.Password = Hash(model.Password,salt);
                dbUserModel.EmailAddress = model.EmailAddress;

                Data.Accessors.UsersAccessor.CreateUser(dbUserModel);
            }
            else
            {
                accountCreationErrors.Add("AccountExists", "The user name you've selected already exists. Please select another");
            }
            return accountCreationErrors;
        }