-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.aspx.cs
114 lines (97 loc) · 3.77 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Newtonsoft.Json;
using PARK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
Connect con;
class JsonClass
{
public string Email { get; set; }
public string Password { get; set; }
public int EventId { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
// Response.Redirect("leaders.html");
if(Session["ttid"] != null)
{
Response.Redirect("garage.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (new User().ValidateUser(txt_email.Value, txt_password.Value))
{
int ttid = new User().getTTId(txt_email.Value);
if (new User().IsSectorSelected(ttid))
{
Session["ttid"] = ttid;
Response.Redirect("garage.aspx");
}
else
{
Session["ttid"] = ttid;
//Redirect user to the sector select
Response.Redirect("selectsector.aspx");
}
}
else if (!new User().ValidateUser(txt_email.Value, txt_password.Value))
{
JsonClass jc = new JsonClass();
jc.Email = txt_email.Value;
jc.Password = txt_password.Value;
jc.EventId = 22;
string json_data = JsonConvert.SerializeObject(jc);
WebClient c = new WebClient();
c.Encoding = System.Text.Encoding.UTF8;
c.Headers[HttpRequestHeader.ContentType] = "application/json";
try
{
string cs = c.UploadString("http://www.silive.in/tt15.rest/api/Student/CheckStudent", json_data);
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
Student stud = new Student();
stud = json_serializer.Deserialize<Student>(cs);
var i = c.ResponseHeaders;
string query = "insert into user(ttid,username,password,email,cash,sector_id,confirmed) values(" + stud.TTId + ",'" + stud.Name + "','" + txt_password.Value + "','" + stud.Email + "',100000,0,1" + ")";
con = new Connect(query);
Session["ttid"] = stud.TTId;
Response.Redirect("selectsector.aspx");
}
catch (WebException ex)
{
HttpWebResponse response = ex.Response as HttpWebResponse;
if (response.StatusCode == HttpStatusCode.NotFound)
{
lbl_error.Text = "You are not registered on Techtrishna. Register Now at Techtrishna 2015 website.";
lbl_error.Visible = true;
}
if (response.StatusCode == HttpStatusCode.Found)
{
con = new Connect();
string q = "update user set password= '" + txt_password.Value + "' where email='" + txt_email.Value + "'";
con = new Connect(q);
int ttid = new User().getTTId(txt_email.Value);
if (new User().IsSectorSelected(ttid))
{
Session["ttid"] = ttid;
Response.Redirect("garage.aspx");
}
else
{
Session["ttid"] = ttid;
//Redirect user to the sector select
Response.Redirect("selectsector.aspx");
}
}
//lbl_error.Text = "Invalid credentials";
}
}
}
}