forked from socioboard/socioboard-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AjaxLogin.aspx.cs
303 lines (265 loc) · 15 KB
/
AjaxLogin.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using SocioBoard.Model;
using SocioBoard.Domain;
using Newtonsoft.Json.Linq;
using SocioBoard.Helper;
using GlobusGooglePlusLib.Authentication;
using System.Configuration;
using SocioBoard;
namespace SocialSuitePro
{
public partial class AjaxLogin : System.Web.UI.Page
{
ILog logger = LogManager.GetLogger(typeof(AjaxLogin));
protected void Page_Load(object sender, EventArgs e)
{
try
{
ProcessRequest();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
logger.Error(ex.StackTrace);
}
}
public void ProcessRequest()
{
if (Request.QueryString["op"] == "login")
{
try
{
string email = Request.QueryString["username"];
string password = Request.QueryString["password"];
Registration regpage = new Registration();
password = regpage.MD5Hash(password);
SocioBoard.Helper.SessionFactory.configfilepath = Server.MapPath("~/hibernate.cfg.xml");
UserRepository userrepo = new UserRepository();
LoginLogs objLoginLogs = new LoginLogs();
LoginLogsRepository objLoginLogsRepository = new LoginLogsRepository();
User user = userrepo.GetUserInfo(email, password);
if (user == null)
{
Response.Write("Invalid Email or Password");
}
else
{
if (user.UserStatus == 1)
{
Session["LoggedUser"] = user;
// List<User> lstUser = new List<User>();
if (Session["LoggedUser"] != null)
{
//SocioBoard.Domain.User.lstUser.Add((User)Session["LoggedUser"]);
//Application["OnlineUsers"] = SocioBoard.Domain.User.lstUser;
//objLoginLogs.Id = new Guid();
//objLoginLogs.UserId = user.Id;
//objLoginLogs.UserName = user.UserName;
//objLoginLogs.LoginTime = DateTime.Now.AddHours(11.50);
//objLoginLogsRepository.Add(objLoginLogs);
Groups objGroups = new Groups();
GroupRepository objGroupRepository = new GroupRepository();
Team objteam = new Team();
TeamRepository objTeamRepository = new TeamRepository();
objGroups = objGroupRepository.getGroupDetail(user.Id);
if (objGroups == null)
{
//================================================================================
//Insert into group
try
{
objGroups = new Groups();
objGroups.Id = Guid.NewGuid();
objGroups.GroupName = ConfigurationManager.AppSettings["DefaultGroupName"];
objGroups.UserId = user.Id;
objGroups.EntryDate = DateTime.Now;
objGroupRepository.AddGroup(objGroups);
objteam.Id = Guid.NewGuid();
objteam.GroupId = objGroups.Id;
objteam.UserId = user.Id;
objteam.EmailId = user.EmailId;
// teams.FirstName = user.UserName;
objTeamRepository.addNewTeam(objteam);
SocialProfile objSocialProfile = new SocialProfile();
SocialProfilesRepository objSocialProfilesRepository = new SocialProfilesRepository();
List<SocialProfile> lstSocialProfile = objSocialProfilesRepository.getAllSocialProfilesOfUser(user.Id);
if (lstSocialProfile != null)
{
if (lstSocialProfile.Count > 0)
{
foreach (SocialProfile item in lstSocialProfile)
{
try
{
TeamMemberProfile objTeamMemberProfile = new TeamMemberProfile();
TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository();
objTeamMemberProfile.Id = Guid.NewGuid();
objTeamMemberProfile.TeamId = objteam.Id;
objTeamMemberProfile.ProfileId = item.ProfileId;
objTeamMemberProfile.ProfileType = item.ProfileType;
objTeamMemberProfile.Status = item.ProfileStatus;
objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
logger.Error("Error : " + ex.Message);
logger.Error("Error : " + ex.StackTrace);
}
//==========================================================================================================
}
BusinessSetting objBusinessSetting = new BusinessSetting();
BusinessSettingRepository objBusinessSettingRepository = new BusinessSettingRepository();
List<BusinessSetting> lstBusinessSetting = objBusinessSettingRepository.GetBusinessSettingByUserId(user.Id);
if (lstBusinessSetting.Count == 0)
{
try
{
List<Groups> lstGroups = objGroupRepository.getAllGroups(user.Id);
foreach (Groups item in lstGroups)
{
objBusinessSetting = new BusinessSetting();
objBusinessSetting.Id = Guid.NewGuid();
objBusinessSetting.BusinessName = item.GroupName;
//objbsnssetting.GroupId = team.GroupId;
objBusinessSetting.GroupId = item.Id;
objBusinessSetting.AssigningTasks = false;
objBusinessSetting.AssigningTasks = false;
objBusinessSetting.TaskNotification = false;
objBusinessSetting.TaskNotification = false;
objBusinessSetting.FbPhotoUpload = 0;
objBusinessSetting.UserId = user.Id;
objBusinessSetting.EntryDate = DateTime.Now;
objBusinessSettingRepository.AddBusinessSetting(objBusinessSetting);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
Response.Write("user");
}
else
{
Response.Write("You are Blocked by Admin Please contact Admin!");
}
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
logger.Error(ex.StackTrace);
}
}
else if (Request.QueryString["op"] == "register")
{
User user = new User();
UserActivation objUserActivation = new UserActivation();
UserRepository userrepo = new UserRepository();
SocioBoard.Helper.SessionFactory.configfilepath = Server.MapPath("~/hibernate.cfg.xml");
Session["AjaxLogin"] = "register";
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
string line = "";
line = sr.ReadToEnd();
JObject jo = JObject.Parse(line);
user.PaymentStatus = "unpaid";
if (!string.IsNullOrEmpty(Request.QueryString["type"]))
{
user.AccountType = Request.QueryString["type"];
}
else
{
user.AccountType = "deluxe";
}
user.CreateDate = DateTime.Now;
user.ExpiryDate = DateTime.Now.AddMonths(1);
user.Id = Guid.NewGuid();
user.UserName = Server.UrlDecode((string)jo["firstname"]) + " " + Server.UrlDecode((string)jo["lastname"]);
user.EmailId = Server.UrlDecode((string)jo["email"]);
user.Password = Server.UrlDecode((string)jo["password"]);
user.UserStatus = 1;
if (!userrepo.IsUserExist(user.EmailId))
{
UserRepository.Add(user);
Session["LoggedUser"] = user;
Response.Write("user");
objUserActivation.Id = Guid.NewGuid();
objUserActivation.UserId = user.Id;
objUserActivation.ActivationStatus = "0";
UserActivationRepository.Add(objUserActivation);
//add value in userpackage
UserPackageRelation objUserPackageRelation = new UserPackageRelation();
UserPackageRelationRepository objUserPackageRelationRepository = new UserPackageRelationRepository();
PackageRepository objPackageRepository = new PackageRepository();
Package objPackage = objPackageRepository.getPackageDetails(user.AccountType);
objUserPackageRelation.Id = new Guid();
objUserPackageRelation.PackageId = objPackage.Id;
objUserPackageRelation.UserId = user.Id;
objUserPackageRelation.PackageStatus = true;
objUserPackageRelationRepository.AddUserPackageRelation(objUserPackageRelation);
SocioBoard.Helper.MailSender.SendEMail(user.UserName, user.Password, user.EmailId, user.AccountType.ToString(), user.Id.ToString());
//MailSender.SendEMail(user.UserName, user.Password, user.EmailId);
// lblerror.Text = "Registered Successfully !" + "<a href=\"login.aspx\">Login</a>";
}
else
{
Response.Write("Email Already Exists !");
}
}
catch (Exception ex)
{
logger.Error(ex.StackTrace);
Console.WriteLine(ex.StackTrace);
}
}
else if (Request.QueryString["op"] == "facebooklogin")
{
SessionFactory.configfilepath = Server.MapPath("~/hibernate.cfg.xml");
string redi = "http://www.facebook.com/dialog/oauth/?scope=publish_stream,read_stream,read_insights,manage_pages,user_checkins,user_photos,read_mailbox,manage_notifications,read_page_mailboxes,email,user_videos,offline_access&client_id=" + ConfigurationManager.AppSettings["ClientId"] + "&redirect_uri=" + ConfigurationManager.AppSettings["RedirectUrl"] + "&response_type=code";
Session["login"] = "facebook";
Response.Write(redi);
}
else if (Request.QueryString["op"] == "googlepluslogin")
{
Session["login"] = "googleplus";
oAuthToken objToken = new oAuthToken();
Response.Write(objToken.GetAutherizationLink("https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.me+https://www.googleapis.com/auth/plus.login"));
}
else if (Request.QueryString["op"] == "removeuser")
{
try
{
if (Session["LoggedUser"] != null)
{
SocioBoard.Domain.User.lstUser.Remove((User)Session["LoggedUser"]);
}
}
catch (Exception Err)
{
logger.Error(Err.StackTrace);
Response.Write(Err.StackTrace);
}
}
}
}
}