Esempio n. 1
0
        protected void btnSubmitEmail_Click(object sender, EventArgs e)
        {
            string type = Request.QueryString["Type"];

            if (auth.checkForAccountEmail(txtUsername.Text.ToString().Replace(" ", string.Empty), true)
                == false && auth.checkForAccountEmail(txtEmailAddress.Text.ToString().Replace(" ", string.Empty), true)
                == false)
            {
                USER   User   = new USER();
                string userID = auth.GenerateRandomUserID();
                User.UserID    = userID.ToString().Replace(" ", string.Empty);
                User.Email     = txtEmailAddress.Text.ToString().Replace(" ", string.Empty);
                User.FirstName = txtFirstName.Text.ToString().Replace(" ", string.Empty);
                User.LastName  = txtLastName.Text.ToString().Replace(" ", string.Empty);
                User.UserImage = "https://upload.wikimedia.org/wikipedia/commons/3/34/PICA.jpg";
                User.UserName  = txtUsername.Text.ToString().Replace(" ", string.Empty);
                if (txtContactNumber.Text.ToString() != "")
                {
                    //if they did enter contact no
                    User.ContactNo = txtContactNumber.Text.ToString().Replace(" ", string.Empty);
                }
                else
                {
                    //if they did'nt enter contact no
                    User.ContactNo = "";
                }
                User.AccountType = "Email";

                //variable to storetemp password
                string tempPassword = "";

                //if a user is being registered
                if (type == "Email")
                {
                    User.UserType = 'C';
                    User.Password = auth.generatePassHash(txtPassword.Text.ToString().Replace(" ", string.Empty));
                }
                //if a employee is being registered by a manager
                else if (type == "NewEmp")
                {
                    User.UserType = 'E';
                    tempPassword  = System.Web.Security.Membership.GeneratePassword(8, 1);
                    User.Password = auth.generatePassHash(tempPassword);
                }
                //if a customer is being registered by a receptionist
                else if (type == "NewCust")
                {
                    User.UserType = 'C';
                    tempPassword  = System.Web.Security.Membership.GeneratePassword(8, 1);
                    User.Password = auth.generatePassHash(tempPassword);
                }

                /*
                 * use the bll.NewUser to creat a new user
                 */

                bool result = false;
                try
                {
                    if (type == "Email" || type == "NewCust")
                    {
                        result = auth.NewUser(User);
                    }
                    else if (type == "NewEmp")
                    {
                        result = handler.addEmployee(User.UserID, null, null, null,
                                                     null, null, User.FirstName, User.LastName, User.UserName, User.Email,
                                                     User.ContactNo, User.Password, User.UserImage, User.PassRestCode);
                    }
                }
                catch (Exception err)
                {
                    function.logAnError("Error Adding Employee | Error: " + err);
                    Response.Redirect("../Error.aspx?Error=Error Adding Employee, Please Try Again Later");
                }

                if (result == true)
                {
                    //if a user is being registered
                    if (type == "Email")
                    {
                        //send an email notification
                        var body = new System.Text.StringBuilder();
                        body.AppendFormat("Hello, " + User.FirstName);
                        body.AppendLine(@"");
                        body.AppendLine(@"You have successfully registered with Cheveux, Using the email address: " + User.Email.ToString() + ".");
                        body.AppendLine(@"Your username is: " + User.UserName.ToString() + "");
                        body.AppendLine(@"");
                        body.AppendLine(@"Make Your First Booking Now: http://sict-iis.nmmu.ac.za/beauxdebut/MakeABooking.aspx");
                        body.AppendLine(@"");
                        body.AppendLine(@"Regards,");
                        body.AppendLine(@"The Cheveux Team");
                        function.sendEmailAlert(User.Email.ToString(), User.FirstName.ToString() + " " + User.LastName.ToString(),
                                                "Welcome To Cheveux",
                                                body.ToString(),
                                                "Accounts Cheveux");
                    }
                    //if a employee is being registered by a manager
                    else if (type == "NewEmp")
                    {
                        //send an email notification
                        var body = new System.Text.StringBuilder();
                        body.AppendFormat("Hello, " + User.FirstName);
                        body.AppendLine(@"");
                        body.AppendLine(@"You have successfully been registered with Cheveux by your manager, Using the email address: " + User.Email.ToString() + ".");
                        body.AppendLine(@"");
                        body.AppendLine(@"Your username is: " + User.UserName.ToString() + "");
                        body.AppendLine(@"Your password is: " + tempPassword + "");
                        body.AppendLine(@"");
                        body.AppendLine(@"Regards,");
                        body.AppendLine(@"The Cheveux Team");
                        function.sendEmailAlert(User.Email.ToString(), User.FirstName.ToString() + " " + User.LastName.ToString(),
                                                "Welcome To Cheveux",
                                                body.ToString(),
                                                "Accounts Cheveux");
                    }
                    //if a customer is being registered by a receptionist
                    else if (type == "NewCust")
                    {
                        //send an email notification
                        var body = new System.Text.StringBuilder();
                        body.AppendFormat("Hello, " + User.FirstName);
                        body.AppendLine(@"");
                        body.AppendLine(@"You have successfully been registered with Cheveux, Using the email address: " + User.Email.ToString() + ".");
                        body.AppendLine(@"");
                        body.AppendLine(@"Your username is: " + User.UserName.ToString() + "");
                        body.AppendLine(@"Your password is: " + tempPassword + "");
                        body.AppendLine(@"");
                        body.AppendLine(@"Visit our site now to view your profile: http://sict-iis.nmmu.ac.za/beauxdebut/Profile.aspx");
                        body.AppendLine(@"");
                        body.AppendLine(@"Regards,");
                        body.AppendLine(@"The Cheveux Team");
                        function.sendEmailAlert(User.Email.ToString(), User.FirstName.ToString() + " " + User.LastName.ToString(),
                                                "Welcome To Cheveux",
                                                body.ToString(),
                                                "Accounts Cheveux");
                    }

                    //if a user is being registered
                    if (type == "Email")
                    {
                        HttpCookie cookie = new HttpCookie("CheveuxRememberMe");
                        cookie.Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(cookie);

                        //log the user in by creating a cookie to manage their state
                        cookie = new HttpCookie("CheveuxUserID");
                        // Set the user id in it.
                        cookie["ID"] = userID;
                        cookie["UT"] = "C";
                        // Add it to the current web response.
                        Response.Cookies.Add(cookie);
                        //go back to the previous page or the home page by default
                        goToPreviousPage();
                        //tell the user the registration was a success on the home page
                        Response.Redirect("../Default.aspx?" + "NU=" + txtFirstName.Text.ToString().Replace(" ", string.Empty));
                    }
                    //if a employee is being registered by a manager
                    else if (type == "NewEmp")
                    {
                        Response.Redirect("../Manager/UpdateEmployee.aspx?Type=NewEmp&empID=" + User.UserID);
                    }
                    //if a customer is being registered by a receptionist
                    else if (type == "NewCust")
                    {
                        //check if the receptionist was in the proccess of makeing a booking
                        goToPreviousPage();
                        Response.Redirect("../Profile.aspx?Action=View&UserID=" + User.UserID);
                    }
                }
                else if (result == false &&
                         (type == "Email" || type == "NewCust"))
                {
                    //open error page
                    Response.Redirect("../Error.aspx?Error='A Error in when authenticating with the Cheveux server'");
                }
                else if (result == false && type == "NewEmp")
                {
                    phAddEmpErr.Visible = true;
                    lblAddEmpErr.Text   = "Unable to add employee at this point in time.<br/>"
                                          + "Please try again later.";
                }
            }
            else
            {
                txtUsername_TextChanged(sender, e);
                txtEmailAddress_TextChanged(sender, e);
            }
        }