示例#1
0
 static void HandleSignUpResult(SignUpStatus status)
 {
     if (status == SignUpStatus.Success)
     {
         Execute.OnUIThread(() =>
         {
             MessageBoxViewModel message = new MessageBoxViewModel();
             message.DisplayName         = AppStrings.SignUpWindowTitle;
             message.Header       = AppStrings.SucceededMessageHeader;
             message.MessageLevel = MessageLevel.Success;
             message.Message      = AppStrings.SignUpSuccessMessage;
             IoC.Get <IWindowManager>().ShowDialog(message);
         });
     }
     else
     {
         var errorMessage = GetSignUpErrorMessage(status);
         Execute.OnUIThread(() =>
         {
             MessageBoxViewModel message = new MessageBoxViewModel();
             message.DisplayName         = AppStrings.SignUpWindowTitle;
             message.Header       = AppStrings.FailedMessageHeader;
             message.MessageLevel = MessageLevel.Exclamation;
             message.Message      = errorMessage;
             IoC.Get <IWindowManager>().ShowDialog(message);
         });
     }
 }
示例#2
0
        public MenuState ExecuteCommand(int index)
        {
            switch ((Command)index)
            {
            case Command.ReadUsername:
                this.ReadUsername();
                return(MenuState.Signup);

            case Command.ReadPassword:
                this.ReadPassword();
                return(MenuState.Signup);

            case Command.SignUp:
                SignUpStatus signUp = UserService.TrySignUpUser(this.Username, this.Password);
                switch (signUp)
                {
                case SignUpStatus.Success:
                    return(MenuState.SuccessfulLogIn);

                case SignUpStatus.DetailsError:
                    this.ErrorMessage = DETAILS_ERROR;
                    return(MenuState.Error);

                case SignUpStatus.UsernameTakenError:
                    this.ErrorMessage = USERNAME_TAKEN_ERROR;
                    return(MenuState.Error);
                }
                break;

            case Command.Back:
                this.ResetSignUp();
                return(MenuState.Back);
            }
            throw new System.InvalidOperationException();
        }
示例#3
0
        private void signUpButtonClicked(object sender, EventArgs e)
        {
            string login       = loginTextBox.Text;
            string pswd        = passwordtextBox.Text;
            string confirmPswd = confirmPasswordtextBox.Text;
            string fname       = fnameTextBox.Text;
            string lname       = lnameTextBox.Text;
            string mail        = emailTextBox.Text;

            // sprawdzanie, czy ktores pole jest puste
            if (login == "" ||
                pswd == "" ||
                confirmPswd == "" ||
                fname == "" ||
                lname == "" ||
                mail == "")    // ale to brzydko wyglada
            {
                signUpStatusLabel.Text = "Every field must be filled";
            }
            else if (pswd != confirmPswd) // czy potwierdzono poprawnie haslo
            {
                signUpStatusLabel.Text = "Both passwords are not equal";
            }
            else if (!CheckMail(mail)) // sprawdzanie struktury maila (podobne do regexa)
            {
                signUpStatusLabel.Text = "Wrong mail address";
            }
            else
            {
                // spróbuj dodać go do bazy
                DbUtil       db     = new DbUtil();
                SignUpStatus status = db.AddUser(
                    new Account(-1, fname, lname, login,
                                pswd, mail, AccountType.USER)
                    );

                switch (status)
                {
                case SignUpStatus.LOGIN_EXISTS:
                    signUpStatusLabel.Text = "User with this login name already exists";
                    break;

                case SignUpStatus.EMAIL_EXISTS:
                    signUpStatusLabel.Text = "You already have account";
                    break;

                case SignUpStatus.OK:
                    DialogResult dialog = MessageBox.Show("Created new account", "Success");
                    SendMail(mail);
                    signUpStatusLabel.Text = "";
                    break;

                case SignUpStatus.CONNECTION_LOST:
                    signUpStatusLabel.Text = "Server is busy. Please try later.";
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Insert new family member
        /// </summary>
        /// <param name="familyMember"></param>
        /// <returns>The family member.</returns>
        public FamilyMember AddMember(FamilyMember familyMember)
        {
            var member = new FamilyMember();

            member.Firstname       = familyMember.Firstname;
            member.Lastname        = familyMember.Lastname;
            member.DateOfBirth     = familyMember.DateOfBirth;
            member.Zipcode         = familyMember.Zipcode;
            member.PhoneNumber     = familyMember.PhoneNumber.RemoveCountyCode();
            member.ProfileImageUrl = familyMember.ProfileImageUrl;
            member.MemberType      = familyMember.MemberType;
            member.Gender          = familyMember.Gender;
            member.CreationDate    = DateTime.UtcNow;
            member.ProfileStatus   = ProfileStatus.InCompleted;
            member.HasTrial        = familyMember.HasTrial;
            member.PromoCode       = familyMember.PromoCode;

            SignUpStatus signupStatus = SignUpStatus.SingedUp;

            if ((familyMember.MemberType == MemberType.Admin || familyMember.MemberType == MemberType.Parent) && !string.IsNullOrEmpty(familyMember.User?.Email) && !string.IsNullOrEmpty(familyMember.User?.Password))
            {
                var passwordSalt = _cryptoService.GenerateSalt();
                var password     = _cryptoService.EncryptPassword(familyMember.User.Email, familyMember.User.Password,
                                                                  passwordSalt);
                familyMember.User.Password     = password;
                familyMember.User.PasswordSalt = passwordSalt;
            }

            var user = new User
            {
                Email        = familyMember.User?.Email,
                Password     = familyMember.User?.Password,
                PIN          = familyMember.User?.PIN,
                PasswordSalt = familyMember.User?.PasswordSalt,
                FamilyID     = familyMember.User == null ? _currentUserService.FamilyID : familyMember.User.FamilyID,
                Family       = (familyMember.User?.FamilyID == 0) ? new Family {
                    Name = familyMember.Lastname, UniqueName = GetFamilyUniqueName(familyMember.Lastname), SignUpStatus = signupStatus
                } : GetFamilyById(familyMember.User != null ? familyMember.User.FamilyID : _currentUserService.FamilyID),
                LoggedOn = DateTime.UtcNow
            };

            member.User = user;
            Repository.Insert(member);

            // Create new default allocation settings, If child member
            if (member.MemberType == MemberType.Child)
            {
                _allocationSettingsService.CreateNew(member.Id);
                _earningsService.CreateNew(member.Id);
                // Update signup progress
                _signUpProgressService.UpdateSignUpProgress(SignUpStatus.AddedChild);
            }

            return(member);
        }
示例#5
0
        // dodanie uzytkownika do tabeli
        // zwraca SignUpStatus
        // w bazie danych nie może powtarzać się email albo login
        public SignUpStatus AddUser(Account account)
        {
            SignUpStatus status = SignUpStatus.OK;

            // Sprawdzenie, czy w bazie jest konto o takim samym loginie/emailu
            try
            {
                conn = new MySqlConnection(connStr);
                conn.Open();

                // zapytanie powinno zwrócić wszystkich użytkowników, którzy mają taki sam login lub email
                string       query = "SELECT login, email FROM accounts WHERE login=@login OR email=@email";
                MySqlCommand cmd   = new MySqlCommand(query, conn);

                cmd.Parameters.AddWithValue("@login", account.login);
                cmd.Parameters.AddWithValue("@email", account.email);


                MySqlDataReader reader = cmd.ExecuteReader();

                // sprawdzanie każdej znalezionej krotki
                while (reader.Read())
                {
                    if (reader.GetString(1).Equals(account.email))
                    {
                        status = SignUpStatus.EMAIL_EXISTS;
                    }
                    else if (reader.GetString(0).Equals(account.login))
                    {
                        status = SignUpStatus.LOGIN_EXISTS;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                status = SignUpStatus.CONNECTION_LOST;
            }
            finally
            {
                conn.Close();
            }

            // jeżeli nie ma takiego uzytkownika w bazie, to go dodaj
            if (status.Equals(SignUpStatus.OK))
            {
                addRow(account);
            }

            return(status);
        }
示例#6
0
        static string GetSignUpErrorMessage(SignUpStatus status)
        {
            switch (status)
            {
            case SignUpStatus.ServerError: return(ErrorStrings.GenericErrorMessage);

            case SignUpStatus.DuplicateUserName: return(ErrorStrings.SignUpFailed_DuplicateUserName);

            case SignUpStatus.DuplicateEmail: return(ErrorStrings.SignUpFailed_DuplicateEmail);

            case SignUpStatus.InvalidEmail: return(ErrorStrings.InvalidEmail);

            case SignUpStatus.InvalidPassword: return(ErrorStrings.SignUpFailed_InvalidPassword);

            default: return(string.Empty);
            }
        }
        /// <summary>
        /// Update signup progress
        /// </summary>
        /// <param name="signUpStatus">Signup status</param>
        /// <param name="familyId">Family identifier</param>
        public void UpdateSignUpProgress(SignUpStatus signUpStatus, int?familyId = null)
        {
            familyId = familyId ?? _currentUserService.FamilyID;
            if (familyId == null)
            {
                return;
            }

            var family = Repository.Table <Family>().Where(m => m.Id == familyId).SingleOrDefault();

            if (family == null)
            {
                throw new InvalidParameterException("Invalid Family!");
            }

            if (family.SignUpStatus != SignUpStatus.Completed)
            {
                switch (family.SignUpStatus)
                {
                case SignUpStatus.SingedUp:
                    if (signUpStatus == SignUpStatus.AddedChild)
                    {
                        family.SignUpStatus = SignUpStatus.AddedChild;
                    }
                    break;

                case SignUpStatus.AddedChild:
                case SignUpStatus.AddedChore:
                    if (signUpStatus == SignUpStatus.AddedChore)
                    {
                        family.SignUpStatus = SignUpStatus.AddedChore;
                    }

                    if (signUpStatus == SignUpStatus.Completed)
                    {
                        family.SignUpStatus = SignUpStatus.Completed;
                    }
                    break;
                }

                Repository.Update(family);
            }
        }
示例#8
0
        private async Task Signup(string email, string username, string password)
        {
            try
            {
                SignUpStatus signupResult = await LoginService.Signup(email, username, password);

                switch (signupResult.Result)
                {
                case SignupResult.Ok:
                    MessageBox.Show("Account was successfully created", "Account created", MessageBoxButton.OK);
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                    return;

                case SignupResult.Error:
                    MessageBox.Show("Error creating account: " + signupResult.Message, "Account not created", MessageBoxButton.OK);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("An error occurred while trying to sign up. Please try again.", "Signup failed", MessageBoxButton.OK);
            }
        }
示例#9
0
        public MenuState ExecuteCommand(int index)
        {
            switch ((Command)index)
            {
            case Command.ReadUsername:
                ReadUsername();
                return(MenuState.Signup);

            case Command.ReadPassword:
                ReadPassword();
                return(MenuState.Signup);

            case Command.SignUp:
                SignUpStatus signUpStatus = UserService.TrySignUpUser(Username, Password);
                switch (signUpStatus)
                {
                case SignUpStatus.Success:
                    return(MenuState.SignedUp);

                case SignUpStatus.DetailsError:
                    ErrorMessage = DETAILS_ERROR;
                    Error        = true;
                    return(MenuState.Error);

                case SignUpStatus.UsernameTakenError:
                    ErrorMessage = USERNAME_TAKEN_ERROR;
                    Error        = true;
                    return(MenuState.Error);
                }
                break;

            case Command.Back:
                ResetSignUp();
                return(MenuState.Back);
            }
            throw new InvalidCommandException();
        }
示例#10
0
 public UserException(SignUpStatus status, string message) : base((int)status, message)
 {
 }
示例#11
0
 public UserAnswer(SignUpStatus status, string answer) : base((int)status, answer)
 {
 }