Пример #1
0
        protected void UnlockAccountBtn_Click(object sender, EventArgs e)
        {
            UnlockResult.Visible = false;
            UnlockError.Visible  = false;

            int userId = int.Parse(SelectedAccount.Value);

            if (userId > 0)
            {
                User lockedUser = UserUtil.GetUser(userId);
                FirebaseUtil.ForgotPassword(lockedUser.Email);
                UserUtil.ValidLogin(lockedUser);
                User user = (User)Session["User"];
                if (user != null)
                {
                    Log.Info(user.Identity + " unlocked an account " + user.Identity);
                }
                else
                {
                    Log.Info("System unlocked an account " + user.Identity);
                }
                UnlockResult.Visible = true;
                UnlockResult.Text    = "Unlocked account " + lockedUser.Identity;
            }
            else
            {
                UnlockError.Visible = true;
                UnlockError.Text    = "Please select an account to unlock";
            }

            ClearFields();
        }
Пример #2
0
        //Validate the user login
        protected bool ValidateLogin(string email, string pass)
        {
            //validates the user's credentials against Firebase
            User user = UserUtil.GetUser(email);

            if (user != null)
            {
                if (user.InvalidLoginCt < 5)
                {
                    user.FirebaseUser = FirebaseUtil.LoginUser(email, pass);
                    if (user.FirebaseUser != null)
                    {
                        UserUtil.ValidLogin(user);
                        Session["User"] = user;
                        return(true);
                    }
                    else
                    {
                        UserUtil.InvalidLogin(user);
                        if ((5 - user.InvalidLoginCt + 1) <= 3)
                        {
                            ErrorLabel2.Text = (5 - user.InvalidLoginCt + 1) + " attempt(s) remaining until account is locked";
                        }
                    }
                }
                else
                {
                    //FirebaseUtil.ForgotPassword(user.Email);
                    //ErrorLabel2.Text = "Account locked, check your email for a password reset link";
                    ErrorLabel2.Text = "Account locked, contact a Venture Creations admin";
                }
            }
            return(false);
        }
Пример #3
0
        protected void ChangePassword_Click(object sender, EventArgs e)
        {
            PasswordChangeError.Visible = true;
            User user = (User)Session["User"];

            if (FirebaseUtil.ForgotPassword(user.Email))
            {
                PasswordChangeError.CssClass = "success";
                PasswordChangeError.Text     = "Check your email for a password reset link";
            }
            else
            {
                PasswordChangeError.Text = "Couldn't send you a reset email";
            }
        }
Пример #4
0
 //Run the follow code when the user want to change their password.
 protected void ChangeBtn_Click(object sender, EventArgs e)
 {
     if (Email.Text.Length > 0)
     {
         if (FirebaseUtil.ForgotPassword(Email.Text))
         {
             ErrorLabel.Text   = "";
             SuccessLabel.Text = "Check your email for a password reset link!";
             Email.Visible     = false;
             changeBtn.Visible = false;
         }
         else
         {
             SuccessLabel.Text = "";
             ErrorLabel.Text   = Email.Text + " is not valid.";
         }
     }
     else
     {
         ErrorLabel.Text = "Please enter your email!";
     }
 }
Пример #5
0
        //Register a new user in the system
        protected void RegisterBtn_Click(object sender, EventArgs e)
        {
            UserCreateResult.Visible = false;
            EmailError.Visible       = false;
            NameError.Visible        = false;
            PasswordError.Visible    = false;
            RoleCompanyError.Visible = false;

            string email             = Email.Text;
            string firstName         = FirstName.Text;
            string lastName          = LastName.Text;
            string pass              = Password.Text;
            string pass2             = PasswordRepeat.Text;
            int    roleId            = int.Parse(SelectedRole.Value);
            int    companyId         = int.Parse(SelectedCompany.Value);
            string displayName       = "";
            bool   verificationEmail = true;

            //Validate that the logged in user has permissions to do this
            //Validate the new user's information
            //Create the new user account
            //Send an email to the new user

            //checks that a role was selected for the user

            if (!UserUtil.DoesUserExist(email))
            {
                if (firstName.Length > 0 && lastName.Length > 0)
                {
                    if (roleId != -1)
                    {
                        if (companyId != -1)
                        {
                            if (pass.Equals(pass2))
                            {
                                if (pass.Length > 7)
                                {
                                    int validPass = ValidatePasswordSecurity(pass);
                                    if (validPass == 0)
                                    {
                                        //creates the user in firebase
                                        Firebase.Auth.User fbUser = FirebaseUtil.CreateNewUser(email, pass, displayName, verificationEmail);

                                        //if the user already exists in firebase, try to log them in
                                        if (fbUser == null)
                                        {
                                            fbUser = FirebaseUtil.LoginUser(email, pass);
                                        }

                                        if (fbUser != null)
                                        {
                                            User u    = UserUtil.CreateUser(roleId, companyId, email, firstName, lastName);
                                            User user = (User)Session["User"];
                                            if (user != null)
                                            {
                                                Log.Info(user.Identity + " created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email);
                                            }
                                            else
                                            {
                                                Log.Info("System created a new " + RoleUtil.GetRole(roleId).RoleName + " account under " + CompanyUtil.GetCompanyName(companyId) + " assigned to " + firstName + " " + lastName + " - " + email);
                                            }
                                            u.FirebaseUser = fbUser;
                                            //display user created msg
                                            UserCreateResult.Visible = true;
                                            UserCreateResult.Text    = "Successfully created user " + u.Identity;
                                        }
                                        else
                                        {
                                            UserCreateResult.CssClass = "error";
                                            UserCreateResult.Visible  = true;
                                            UserCreateResult.Text     = "Error creating user in Firebase";
                                        }
                                    }
                                    else
                                    {
                                        PasswordError.Visible = true;
                                        if (validPass == 1)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 uppercase";
                                        }
                                        else if (validPass == 2)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 lowercase";
                                        }
                                        else if (validPass == 3)
                                        {
                                            PasswordError.Text = "Password must contain at least 1 number";
                                        }
                                        else
                                        {
                                            PasswordError.Text = "Unknown password error";
                                        }
                                    }
                                }
                                else
                                {
                                    //display user failed to be created msg
                                    PasswordError.Visible = true;
                                    PasswordError.Text    = "Password must be at least 8 chars";
                                }
                            }
                            else
                            {
                                //throw error, passwords don't match
                                PasswordError.Visible = true;
                                PasswordError.Text    = "Passwords don't match";
                            }
                        }
                        else
                        {
                            //throw error, please select company for user
                            RoleCompanyError.Visible = true;
                            RoleCompanyError.Text    = "Please select a company";
                        }
                    }
                    else
                    {
                        //throw error, please select role for new user
                        RoleCompanyError.Visible = true;
                        RoleCompanyError.Text    = "Please select a role";
                    }
                }
                else
                {
                    NameError.Visible = true;
                    NameError.Text    = "Please enter a first and last name";
                }
            }
            else
            {
                EmailError.Visible = true;
                EmailError.Text    = "Email already in use";
            }

            ClearFields();
        }