예제 #1
0
        public ActionResult SignUp(SignUpModel signUpModel)
        {
            try
            {
                if(ModelState.IsValid)
                {
                    if(!this.account.IsUserLoginIDExist(signUpModel.Email))
                    {
                        this.account.AddUserToDatabase(signUpModel);
                        FormsAuthentication.SetAuthCookie(signUpModel.Email, false);

                        var accountId = this.account.GetUserId(signUpModel.Email);

                        // Email notification
                        dynamic email = new Email("Welcome");
                        email.UserEmailAddress = signUpModel.Email;
                        email.Send();

                        return RedirectToAction("Create", "Character");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "A user with this email address already exists");
                    }
                }
            }
            catch
            {
                return View(signUpModel);
            }

            return View(signUpModel);
        }
예제 #2
0
        /// <summary>
        /// Adds a user entry to the database based on the information passed from the SignUpModel
        /// </summary>
        /// <param name="signUpModel">Contains all of the account information</param>
        public void AddUserToDatabase(SignUpModel signUpModel)
        {
            this.Id = Guid.NewGuid();
            this.EmailAddress = signUpModel.Email;
            this.Password = HashPassword(signUpModel.Password);
            this.IsAdmin = false;
            this.EmailNotification = false;

            this.db.Accounts.Add(this);
            this.db.SaveChanges();
        }