Beispiel #1
0
        public bool CreateAccount(RegisterViewModel newAccount, out string outputMessage)
        {
            if (!global.IsUniqueEmailAddress(newAccount.EmailAddress))
            {
                outputMessage = Resources.Processing.ProcessEmailExists;
                return(false);
            }
            if (!global.IsUniqueUsername(newAccount.Username))
            {
                outputMessage = Resources.Processing.ProcessUsernameExists;
                return(false);
            }

            Account registerAccount = new Account();

            registerAccount.EmailAddress = newAccount.EmailAddress.ToLower();
            registerAccount.Username     = newAccount.Username;
            registerAccount.Password     = Crypto.SHA1(newAccount.Password);;
            registerAccount.ContactName  = newAccount.ContactName;
            registerAccount.Country      = (newAccount.Country != null) ? newAccount.Country : "Canada";
            registerAccount.State        = (newAccount.State != null) ? newAccount.State : "ON";
            registerAccount.City         = newAccount.City;
            registerAccount.Phone        = newAccount.Phone;
            db.Account.Add(registerAccount);
            db.SaveChanges();

            AccountDetail registerDetails = new AccountDetail();

            registerDetails.AccountId         = registerAccount.AccountId;
            registerDetails.AccountLevel      = 1;
            registerDetails.AccountStatus     = 1;
            registerDetails.SecurityQuestionA = newAccount.SecurityQuestionA;
            registerDetails.SecurityQuestionB = newAccount.SecurityQuestionB;
            registerDetails.SecurityAnswerA   = newAccount.SecurityAnswerA;
            registerDetails.SecurityAnswerB   = newAccount.SecurityAnswerB;
            db.AccountDetail.Add(registerDetails);
            db.SaveChanges();

            outputMessage = newAccount.Username + " is now registered";
            return(true);
        }
        public bool ChangeUsername(SettingUsernameViewModel settingForm, out string outputMessage)
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account userAccount  = global.GetAccount(emailAddress);

            if (userAccount != null)
            {
                if (userAccount.Username.ToLower() == settingForm.OldUsername.ToLower())
                {
                    if (global.IsUniqueUsername(settingForm.NewUsername))
                    {
                        try
                        {
                            userAccount.Username = settingForm.NewUsername;
                            db.SaveChanges();
                            outputMessage = string.Format(Resources.Processing.ProcessSettingsConfirmed, "username");
                            return(true);
                        }
                        catch
                        {
                            outputMessage = Resources.Processing.ProcessError;
                            return(false);
                        }
                    }
                    else
                    {
                        outputMessage = Resources.Processing.ProcessUsernameExists;
                        return(false);
                    }
                }
                else
                {
                    outputMessage = Resources.Processing.ProcessUsernameNotFound;
                    return(false);
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }