Exemplo n.º 1
0
        protected void BtnReset_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                int success = 0;
                if (Request.QueryString["id"] == "password")
                {
                    success = AdminUserDataLayer.RequestPasswordReset(reset.Text);

                    if (success == 1)
                    {
                        ConfirmLbl.Text      = "Email has been sent to reset password";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Green;
                    }
                    else if (success == 2)
                    {
                        ConfirmLbl.Text      = "Username could not be found";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        ConfirmLbl.Text      = "Reset password link has already been sent to your email.";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Red;
                    }
                }
                else if (Request.QueryString["id"] == "username")
                {
                    success = AdminUserDataLayer.RequestUserName(reset.Text);


                    if (success == 1)
                    {
                        ConfirmLbl.Text      = "Your username has been sent to the registered email.";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Green;
                    }
                    else if (success == 2)
                    {
                        ConfirmLbl.Text      = "Email provided is either invalid or does not exist in admin database.";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        ConfirmLbl.Text      = "There has been an error requesting username. Please speak to administration.";
                        ConfirmLbl.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            var user = AdminUserDataLayer.LogIn(UserName.Text, Password.Text);

            if (user.GetType() == typeof(AdminUser))
            {
                AdminUser admin = (AdminUser)user;
                Session["AdminUser"] = admin;
                Session["Name"]      = admin.FirstName + " " + admin.LastName;
                Session["login"]     = "******";
                HttpCookie cookie = Request.Cookies["AdminUser"];

                if (checkboxRemeber.Checked)
                {
                    if (cookie == null)
                    {
                        cookie = new HttpCookie("AdminUser");
                    }

                    cookie["username"] = UserName.Text;
                    cookie["password"] = Password.Text;
                    cookie.Expires     = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(cookie);
                }
                else
                {
                    if (cookie != null)
                    {
                        cookie.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(cookie);
                    }
                }
                Server.Transfer("Default.aspx");
            }
            else
            {
                if (user.ToString() == "Account Locked. Please Contact Administrator")
                {
                    DataRetrieval      retrieve = new DataRetrieval();
                    List <CoachRoster> roster   = retrieve.SelectAllCoaches();
                    Cache["CoachRoster"] = roster;
                }
                InvalidLabel.Text      = user.ToString();
                InvalidLabel.ForeColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 3
0
        protected void EnableUser(object sender, GridViewCommandEventArgs e)
        {
            string name = e.CommandArgument.ToString();

            string[] names     = name.Split(' ');
            string   firstName = names.First();
            string   lastName  = names.Last();
            int      unlocked  = 0;

            List <LockedUser> user = AdminUserDataLayer.GetLockedUsers();

            foreach (LockedUser lockedUser in user)
            {
                if (lockedUser.FirstName == firstName && lockedUser.LastName == lastName)
                {
                    if (lockedUser.Role == "coach")
                    {
                        unlocked = AdminUserDataLayer.EnableUserAccount(firstName, lastName);

                        if (unlocked > 0)
                        {
                            Models.Correspondence.Email.AccountUnlockedConfirmation(lockedUser.FirstName, lockedUser.LastName, lockedUser.Email);
                            List <CoachRoster> roster = (List <CoachRoster>)Cache["CoachRoster"];
                            CoachRoster        coach  = roster.SingleOrDefault(x => x.Name == firstName + " " + lastName);
                            int index = roster.IndexOf(coach);
                            roster.RemoveAt(index);
                            coach.IsLocked = "Access";
                            roster.Insert(index, coach);
                            CoachRosterGridView.DataSource = roster;
                            CoachRosterGridView.DataBind();
                            LblError.Text      = "Account unlocked. Email notification has been sent to user";
                            LblError.ForeColor = System.Drawing.Color.Green;
                        }
                    }
                    else
                    {
                        LblError.Text      = "If you are a manager you will need to contact the IT Department to unlock your account";
                        LblError.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string uid = Request.QueryString["uid"];

                if (uid != null)
                {
                    bool valid = AdminUserDataLayer.PasswordResetLinkValid(uid);

                    if (!valid)
                    {
                        Server.Transfer("ErrorPage.aspx");
                    }
                }
                else
                {
                    Server.Transfer("ErrorPage.aspx");
                }
            }
        }
Exemplo n.º 5
0
        protected void BtnChangePassword_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                AdminUser user        = (AdminUser)Session["AdminUser"];
                string    newPassWord = newPass.Text;

                string currentPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(currentPass.Text, "SHA1");
                string newPassword     = FormsAuthentication.HashPasswordForStoringInConfigFile(newPassWord, "SHA1");
                int    rowAffected     = 0;

                if (user.Password == currentPassword)
                {
                    rowAffected = AdminUserDataLayer.ChangeUserPassword(user.Id, newPassword);
                }

                if (rowAffected > 0)
                {
                    //Models.Correspondence.Email.PasswordChangeConfirmation(user.FirstName, user.LastName, user.UserName, newPassWord, user.Role, user.Email);
                    LblConfirm.Text       = "Password successfully changed.";
                    LblConfirm.ForeColor  = System.Drawing.Color.Green;
                    PasswordPanel.Visible = false;
                    currentPass.Text      = "";
                    newPass.Text          = "";
                    confirmPass.Text      = "";
                    HttpCookie cookie = Request.Cookies["AdminUser"];
                    if (cookie != null)
                    {
                        cookie.Values.Remove("password");
                        cookie["password"] = newPassWord;
                        Response.Cookies.Add(cookie);
                    }
                }
                else
                {
                    LblConfirm.Text      = "Password could not be changed. Please see IT department.";
                    LblConfirm.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
Exemplo n.º 6
0
        protected void BtnReset_Click(object sender, EventArgs e)
        {
            string newPassword = NewPassword.Text;

            string[] arr = AdminUserDataLayer.ResetPassword(Request.QueryString["uid"], newPassword);

            if (arr != null)
            {
                int sent = 1; //Models.Correspondence.Email.SendPasswordChangeConfirmation(newPassword, arr[0], arr[1], arr[2], arr[3]);
                if (sent == 1)
                {
                    confirmLabel.Text      = "Password has been reset. Email confirmation has been sent with the details";
                    confirmLabel.ForeColor = System.Drawing.Color.Green;

                    HttpCookie cookie = Request.Cookies["AdminUser"];


                    if (cookie != null)
                    {
                        cookie.Values.Remove("password");
                        cookie["password"] = newPassword;
                        Response.Cookies.Add(cookie);
                    }
                }
                else
                {
                    confirmLabel.Text      = "Email could not be sent";
                    confirmLabel.ForeColor = System.Drawing.Color.Red;
                }
            }
            else
            {
                confirmLabel.Text      = "Username could not be found";
                confirmLabel.ForeColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 7
0
        protected void BtnRegister_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int coachId = int.Parse(CoachId.Text);


                if (Cache["CoachRoster"] == null)
                {
                    DataRetrieval      retrieve    = new DataRetrieval();
                    List <CoachRoster> coachRoster = retrieve.SelectAllCoaches();
                    Cache.Insert("CoachRoster", coachRoster);
                }
                List <CoachRoster> roster = (List <CoachRoster>)Cache["CoachRoster"];
                var exist = roster.Find(x => x.CoachNumber == coachId);

                //Write code here to check first and last name of the coach 'exist' against first and last name entered in text fields

                if (exist != null)
                {
                    string[] name = exist.Name.Split(' ');


                    if (name[0] == FirstName.Text && name[1] == LastName.Text)
                    {
                        int returnCode = AdminUserDataLayer.Register(Password.Text, FirstName.Text, LastName.Text, Email.Text, UserName.Text, "coach");

                        if (returnCode == -1)
                        {
                            UserExists.Text      = "Username is already in use. Please try again";
                            UserExists.ForeColor = System.Drawing.Color.Red;
                        }
                        else if (returnCode == -2)
                        {
                            UserExists.Text      = "Email is already registered to another user.";
                            UserExists.ForeColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            Models.Correspondence.Email.RegistrationConfirmation(UserName.Text, Password.Text, FirstName.Text, LastName.Text, Email.Text, exist.CoachNumber);
                            UserExists.Text      = "Succesfull Registration. Email Confirmation has been sent to your email";
                            UserExists.ForeColor = System.Drawing.Color.Green;
                            CoachId.Text         = "";
                            FirstName.Text       = "";
                            LastName.Text        = "";
                            Email.Text           = "";
                            UserName.Text        = "";
                            Password.Text        = "";
                        }
                    }
                    else
                    {
                        UserExists.Text      = "Coach name is either invalid or Coach Id is already assigned";
                        UserExists.ForeColor = System.Drawing.Color.Red;
                    }
                }
                else
                {
                    UserExists.Text      = "Coach Number does not exists in database. Please see Administration or try again";
                    UserExists.ForeColor = System.Drawing.Color.Red;
                }
            }
        }