Пример #1
0
        public void performApplicantSignUp()
        {
            // checking if datamembers/fields are empty
            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(firstName) && !string.IsNullOrWhiteSpace(lastName) &&
                !string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(email) && !string.IsNullOrWhiteSpace(gender) && resumeSignup.HasFile && System.IO.Path.GetExtension(resumeSignup.PostedFile.FileName) == ".pdf")
            {
                try
                {
                    con = new SqlConnection(s);
                    con.Open();
                    q   = "select * from applicant where username=@username";
                    cmd = new SqlCommand(q, con);
                    cmd.Parameters.AddWithValue("@username", username);
                    dr = cmd.ExecuteReader();

                    dr.Read();
                    // checking if username already exists
                    if (dr.HasRows)
                    {
                        usernameErr.Visible = true;
                        usernameErr.Text    = "username already exists";
                        dr.Close();
                    }
                    else
                    {
                        dr.Close();

                        //letting user sign up
                        PasswordHash hash           = new PasswordHash(password);
                        byte[]       hashedpassword = hash.ToArray();

                        String resumeLocation = "resumes/" + DateTime.Now.ToString("yyyymmddMMss") + resumeSignup.FileName;
                        resumeSignup.SaveAs(Server.MapPath(resumeLocation));

                        q   = "insert into applicant values(@username, @firstname, @lastname, @email, @resumelocation, @gender, @pass)";
                        cmd = new SqlCommand(q, con);
                        cmd.Parameters.AddWithValue("@username", username);
                        cmd.Parameters.AddWithValue("@firstname", firstName);
                        cmd.Parameters.AddWithValue("@lastname", lastName);
                        cmd.Parameters.AddWithValue("email", email);
                        cmd.Parameters.AddWithValue("@resumelocation", resumeLocation);
                        cmd.Parameters.AddWithValue("@gender", gender);
                        cmd.Parameters.AddWithValue("@pass", hashedpassword);

                        cmd.ExecuteNonQuery();

                        Response.Redirect("/login.aspx?status=success");
                    }
                }
                catch (Exception err)
                {
                    Response.Write(err.Message);
                }
                finally
                {
                    con.Close();
                }
            }
            else
            {
                // individual checking of data members/fields
                if (string.IsNullOrWhiteSpace(username))
                {
                    usernameErr.Visible = true;
                    usernameErr.Text    = "username is required";
                }
                if (string.IsNullOrWhiteSpace(firstName))
                {
                    firstNameErr.Visible = true;
                    firstNameErr.Text    = "first name is required";
                }
                if (string.IsNullOrWhiteSpace(lastName))
                {
                    lastNameErr.Visible = true;
                    lastNameErr.Text    = "last name is required";
                }
                if (string.IsNullOrWhiteSpace(email))
                {
                    emailErr.Visible = true;
                    emailErr.Text    = "email is required";
                }
                if (string.IsNullOrWhiteSpace(password))
                {
                    passwordErr.Visible = true;
                    passwordErr.Text    = "password is required";
                }
                if (string.IsNullOrWhiteSpace(gender))
                {
                    genderErr.Visible = true;
                    genderErr.Text    = "gender is required";
                }

                if (resumeSignup.HasFile != true || System.IO.Path.GetExtension(resumeSignup.PostedFile.FileName) != ".pdf")
                {
                    resumeErr.Visible = true;
                    resumeErr.Text    = "upload a valid .pdf resume file";
                }
            }
        }