LoginHelper.cs
9.06 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using ADAM.AIAHTML5.API.Models;
using System.Data;
using ADAM.AIAHTML5.API.Constants;
using log4net;
using ADAM.AIA50.BusinessLayer.Utility;
namespace ADAM.AIAHTML5.API.Helper
{
public class LoginHelper
{
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
internal AccountTransactInfo buildAdminTransactLicenseInfos(AccountTransactInfo accountTransactInfo)
{
accountTransactInfo.licenseEditionId = EditionHelper.GetInstance().GetHighestPriortyEdition().ToString();
accountTransactInfo.licenseTermCondition = Convert.ToInt16(1).ToString();
accountTransactInfo.licenseModesty = "true";
accountTransactInfo.licenseTypeId = "5";//TEST
accountTransactInfo.licenseId = "-1";
return accountTransactInfo;
}
internal AccountTransactInfo buildAccountTransactLicenseInfos(int userId, AccountTransactInfo accountTransactInfo ,User userInfo)
{
Hashtable objLicEdition = null;
objLicEdition = this.GetUserLicenceEditionDetail(userId,userInfo);
accountTransactInfo.accountNumber = objLicEdition[LoginConst.ACCOUNT_NUMBER].ToString();
accountTransactInfo.licenseTypeId = objLicEdition[LoginConst.LICENSE_TYPE_ID].ToString();
accountTransactInfo.licenseEditionIsActive = Convert.ToBoolean(objLicEdition[LoginConst.LICENSE_ACTIVE]).ToString();
accountTransactInfo.licenseId = Convert.ToInt32(objLicEdition[LoginConst.LICENSE_ID]).ToString();
accountTransactInfo.licenseEditionId = Convert.ToByte(objLicEdition[LoginConst.EDITION_ID]).ToString();
accountTransactInfo.licenseTotalLogin = Convert.ToUInt16(objLicEdition[LoginConst.TOTAL_LOGIN]).ToString();
accountTransactInfo.licenseModesty = Convert.ToBoolean(objLicEdition[LoginConst.MODESTY_SETTING]).ToString();
CheckLicenseStatus(userInfo);
accountTransactInfo.licenseIsExpired = userInfo.IsSubscriptionExpired;
accountTransactInfo.licenseExpirationDate = userInfo.SubscriptionExpirationDate;
bool r = (bool)objLicEdition[LoginConst.TERM_CONDITION];
accountTransactInfo.licenseTermCondition = Convert.ToInt16(r).ToString();
return accountTransactInfo;
}
private static void CheckLicenseStatus(User userInfo)
{
//05.1 For normal user need to get the license details, get the license id for authenticated user
//int licenseId, editionId;
//AIAHTML5.API.Models.Users.getLicenseIdForThisUser(userInfo.Id, out licenseId, out editionId);
//userInfo.LicenseId = licenseId;
//userInfo.EditionId = editionId;
//05.2 get license details
userInfo.LicenseInfo = AIAHTML5.API.Models.Users.getLicenseDetails(userInfo.LicenseId);
if (userInfo.LicenseInfo != null)
{
//05.3 get licenseSubscription details
userInfo.LicenseSubscriptions = AIAHTML5.API.Models.Users.getLicenseSubscriptionDetails(userInfo.LicenseId);
//05.4 check the License expiration irespective of either user is active or not because on AIA
//we shows the License expiration message for inactive users too
string expirationDate = null;
bool isLicenseExpired = false;
if (userInfo.LicenseSubscriptions != null)
{
isLicenseExpired = AIAHTML5.API.Models.Users.checkIfLicenseExpired(userInfo.LicenseSubscriptions, out expirationDate);
}
if (isLicenseExpired)
{
userInfo.IsSubscriptionExpired = isLicenseExpired;
userInfo.SubscriptionExpirationDate = expirationDate;
}
}
else
{
logger.Debug("userInfo.LicenseInfo is null for userInfo.LicenseId= " + userInfo.LicenseId);
}
}
internal AccountTransactInfo buildAccountTransactUserInfos(AccountTransactInfo accountTrasactInfo, String providedPassword, String expectedPassword, User userInfo)
{
accountTrasactInfo.userId = userInfo.Id.ToString();
accountTrasactInfo.providedPassword = providedPassword;
accountTrasactInfo.expectedPassword = expectedPassword;
accountTrasactInfo.userTypeId = userInfo.UserTypeId.ToString();
accountTrasactInfo.userCreatorId = userInfo.CreatorId.ToString();
try
{
if(userInfo.DeactivationDate!= null)
{
accountTrasactInfo.userDeactivationDate =Convert.ToString(userInfo.DeactivationDate);
}
}
catch(Exception ex)
{
logger.Error("exception at DeactivationDate on buildAccountTransactUserInfos method for user id: "+ accountTrasactInfo.userId);
}
accountTrasactInfo.userIsActive = userInfo.IsActive.ToString();
accountTrasactInfo.userLoginId = userInfo.LoginId.ToString();
return accountTrasactInfo;
}
internal AccountTransactInfo buildAccountTransactConcurrentUserInfos(AccountTransactInfo accountTrasactInfo, String providedPassword, String expectedPassword, ADAM.AIAHTML5.API.Models.User userInfo)
{
buildAccountTransactUserInfos(accountTrasactInfo, providedPassword, expectedPassword, userInfo);
//AMI IMP tHING TO BE NOTICE
accountTrasactInfo.usersLoggedIn = (string)SessionManager.GetInstance().CountSession(int.Parse(accountTrasactInfo.licenseId), byte.Parse(accountTrasactInfo.licenseEditionId)).ToString();
return accountTrasactInfo;
}
// get user licence and edition detail
private Hashtable GetUserLicenceEditionDetail(Int32 UserId,User userInfo)
{ // TO DO: Check follwing functionlity can break in small function
Hashtable objHashUserLicDetail = new Hashtable();
// Get detail from User 2 Licence Edition table
DataTable dtUser2Lic = DBModel.getAIALicenseEditionDetails(UserId);
if (dtUser2Lic.Rows.Count == 0)
{
//intErrorID = ErrorHelper.E_USER_NOT_MAP_TO_LICENCE_EDITION;
//errors.Add(ErrorHelper.E_USER_NOT_MAP_TO_LICENCE_EDITION);
//AMI TO DO
userInfo.LoginFailureCauseId = ErrorHelper.E_USER_NOT_MAP_TO_LICENCE_EDITION;
return objHashUserLicDetail;
}
//AdminDAL.AdminDal.AIAUserToLicenseEditionRow rowLicEd = (AdminDAL.AdminDal.AIAUserToLicenseEditionRow)dtUser2Lic.Rows[0];
Int32 intLicenceEditionId = Convert.ToInt32(dtUser2Lic.Rows[0]["LicenseEditionId"]);
//// Get detail form License 2 Editions table
DataTable dtLic2Edition = DBModel.getLicenseEditionById(intLicenceEditionId);
if (dtLic2Edition.Rows.Count == 0)
{
//intErrorID = ErrorHelper.E_NO_ROW_FOUND_LICENCE_TO_EDITION_TABLE;
userInfo.LoginFailureCauseId = ErrorHelper.E_NO_ROW_FOUND_LICENCE_TO_EDITION_TABLE;
return objHashUserLicDetail;
}
//AdminDAL.AdminDal.LicenseToEditionRow rowLic2Edition = (AdminDAL.AdminDal.LicenseToEditionRow)dtLic2Edition.Rows[0];
Int32 licenseId = Convert.ToInt32(dtLic2Edition.Rows[0]["LicenseId"]);
//// get detail from licence tables
//LicenseTableAdapter adpLicence = new LicenseTableAdapter();
//AdminDAL.AdminDal.LicenseDataTable dtLicence = new AdminDAL.AdminDal.LicenseDataTable();
// usp_GetLicenseByLicenseId
DataTable dtLicence = DBModel.getLicenseByLicenseId(licenseId);
if (dtLicence.Rows.Count == 0)
{
userInfo.LoginFailureCauseId = ErrorHelper.E_NO_ROW_FOUND_LICENCE_TABLE;
return objHashUserLicDetail;
}
//AdminDAL.AdminDal.LicenseRow rowLicence = (AdminDAL.AdminDal.LicenseRow)dtLicence.Rows[0];
objHashUserLicDetail.Add(LoginConst.LICENSE_ID, dtLicence.Rows[0]["Id"]);
objHashUserLicDetail.Add(LoginConst.LICENSE_ACTIVE, dtLicence.Rows[0]["IsActive"]);
objHashUserLicDetail.Add(LoginConst.LICENSE_TYPE_ID, dtLicence.Rows[0]["LicenseTypeId"]);
objHashUserLicDetail.Add(LoginConst.ACCOUNT_NUMBER, dtLicence.Rows[0]["AccountNumber"]);
objHashUserLicDetail.Add(LoginConst.TOTAL_LOGIN, dtLicence.Rows[0]["TotalLogins"]);
objHashUserLicDetail.Add(LoginConst.EDITION_ID, dtLicence.Rows[0]["EditionId"]);
objHashUserLicDetail.Add(LoginConst.TERM_CONDITION, dtLicence.Rows[0]["IsTermsAccepted"]);
objHashUserLicDetail.Add(LoginConst.MODESTY_SETTING, dtLicence.Rows[0]["IsModesty"]);
return objHashUserLicDetail;
}
}
}