protected void btnLogin_Click(object sender, EventArgs e)
        {
            v.SetUser(new User(txtEmail.Text, txtPassword.Text));

            try
            {
                bool userValid = v.UserValid();

                if (userValid)
                {
                    Int32 userId = Database.UserId(v.GetUser());
                    userInfo["isAuth"] = "true";
                    userInfo["userId"] = userId.ToString();
                    userInfo.Expires   = DateTime.Now.AddMinutes(10);
                    if (userId == 0)
                    {
                        throw new Exception("This user does not exist");
                    }
                    Response.Cookies.Add(userInfo);
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    throw new Exception("Please enter a valid Email/Password");
                }
            }
            catch (Exception ex)
            {
                alertBody.Text = "<div ID=\"alert\" class=\"alert alert-danger\">" + ex.Message + "</div>";
            }
        }
Exemple #2
0
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     if (txtUsername.Text != string.Empty)
     {
         Session["Username"] = txtUsername.Text;
         Session["User"]     = v.GetUser();
     }
     Response.Redirect("CreateAccount.aspx");
 }