-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginPage.aspx.cs
82 lines (68 loc) · 2.83 KB
/
loginPage.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using HandicappedDriver.Bridge;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows;
namespace HandicappedDriver
{
public partial class loginPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string user = txtUsername.Text;
string pass = txtPassword.Text;
Facade f = new Facade();
// check if the username contains '@uco.edu'
bool isFound = user.Contains("@uco.edu");
if (!isFound)
{
user += "@uco.edu";
}
bool result = Facade.Login(user,pass);
MessageBox.Show(result +"");
// An opinion:- if the user is new and does not exist in the database. Redirect them to create account. Pass in a parameter to denote that
// it is a new user. If the parameter is true, do not go to the home page unless the information has been sucessfully saved. This way we
// don't have worry about disabling the buttons in other page.
if (Facade.CreateDriver(user) == true)
{
Response.Redirect("createAccount.aspx");
}
else if (result)
{
int uid = Facade.Login_GetID(user, pass);
if (uid > 0)
{
// if the user is legit go to home page
DriverData driver = Facade.GetDriverFull(uid);
int usrid_pg = (int)driver.Id;
// assuming userid_pg is the user id, go to home page
// write cookies
HttpCookie user_ID_cookie = new HttpCookie("USER_ID");
user_ID_cookie["USER_ID"] = user;
user_ID_cookie.Expires = DateTime.Now.AddHours(2);
Response.Cookies.Add(user_ID_cookie);
Response.Redirect("homePage.aspx");
}
}
else
{
string msg = "Your profile does not match in our existing database. Please update your profile befor you can continue.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(msg);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
Response.Redirect("createAccount.aspx");
}
}
}
}