-
Notifications
You must be signed in to change notification settings - Fork 0
/
bypass.aspx.cs
152 lines (139 loc) · 5.22 KB
/
bypass.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using sysExtension;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI.HtmlControls;
using System.Configuration;
public partial class bypass : System.Web.UI.Page
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
public HtmlGenericControl SetBody
{
get { return this.bodyMain; }
}
private void SetBodyEventOnLoad(string myFunc)
{
bodyMain.Attributes.Add("onLoad", myFunc);
}
protected void Page_Load(object sender, EventArgs e)
{
string str = Request.QueryString["strad"];
string sm = Request.QueryString["smod"];
string sAD = "";
if (!string.IsNullOrEmpty(sm))
{
if (!string.IsNullOrEmpty(str))
{
hdfUserAD.Value = STCrypt.Decrypt(str);
}
}
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static CResultLogin Login(string sUserName, string sPassword, string sMode)
{
CResultLogin result = new CResultLogin();
UserAcc ua = new UserAcc();
if (!string.IsNullOrEmpty(sUserName))
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
sUserName = sUserName.Trims();
sPassword = sPassword.Trims();
var query = db.mTUser.FirstOrDefault(w => w.Username == sUserName && w.cDel == "N" && w.cActive == "Y");
if (query != null)
{
if (sPassword == ConfigurationManager.AppSettings["DefaultPass"].ToString())
{
var qRole = db.mTUserInRole.FirstOrDefault(w => w.nUID == query.ID);
if (qRole != null)
{
var qRoleName = db.mTUserRole.FirstOrDefault(w => w.ID == qRole.nRoleID);
ua.nUserID = query.ID;
ua.sFullName = query.Firstname + " " + query.Lastname;
ua.nRoleID = qRole.nRoleID;
ua.sActionRoleName = qRoleName != null ? qRoleName.Name : "";
UserAcc.SetObjUser(ua);
result.Status = SystemFunction.process_Success;
}
else
{
result.Status = SystemFunction.process_Failed;
result.Msg = "Not found role !";
}
}
else
{
result.Status = SystemFunction.process_Failed;
result.Msg = "Incorrect pasword !";
}
}
else
{
result.Status = SystemFunction.process_Failed;
result.Msg = "Not found user !";
}
}
return result;
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static sysGlobalClass.CResutlWebMethod SelectedRole(string sUserID, string sRoleID)
{
sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod();
if (new bypass().SetUserLogin(sUserID, sRoleID))
{
result.Status = SystemFunction.process_Success;
result.Content = "epi_mytask.aspx";
}
else
{
result.Status = SystemFunction.process_Failed;
result.Msg = "data not found";
}
return result;
}
private bool SetUserLogin(string sUserID, string sRoleID)
{
int nUserID = SystemFunction.ParseInt(sUserID);
int nRoleID = SystemFunction.ParseInt(sRoleID);
var dataUser = db.mTUser.FirstOrDefault(w => w.ID == nUserID);
var dataRole = db.mTUserRole.FirstOrDefault(w => w.ID == nRoleID);
var lst_RoleAdmin = db.TMenu_Permission.Where(w => w.nUserID == nUserID && w.nRoleID == nRoleID).ToList(); // Role_Admin
var lst_RoleOther = db.mTUser_FacilityPermission.Where(w => w.nUserID == nUserID && w.nRoleID == nRoleID).ToList(); // Role_Other
var lstDataRole = db.mTUserRole.ToList();// Query Role_Name
if (dataUser != null && dataRole != null)
{
string sNameRole = lstDataRole.Any() ? lstDataRole.First(w => w.ID == nRoleID).Name : "";
UserAcc us = new UserAcc();
us.nUserID = dataUser.ID;
us.sFullName = dataUser.Firstname + " " + dataUser.Lastname;
us.nRoleID = lst_RoleAdmin.Any() ? lst_RoleAdmin.First().nRoleID : lst_RoleOther.Any() ? lst_RoleOther.First().nRoleID : 0;
us.sActionRoleName = sNameRole;
UserAcc.SetObjUser(us);
return true;
}
else
{
return false;
}
}
[Serializable]
public class CResultLogin : sysGlobalClass.CResutlWebMethod
{
public int nUserID { get; set; }
public string sFullName { get; set; }
public string sRoleName { get; set; }
public List<UserAcc.TDataRole> TDataRole { get; set; }
}
[Serializable]
public class TDataRole
{
public int nRoleID { get; set; }
public string sRoleName { get; set; }
}
}