protected void btnLogin_Click(object sender, EventArgs e)
{
#region Remember Me
if (check.Checked == true)
{
Response.Cookies["UName"].Value = txtUserName.Text;
Response.Cookies["PWD"].Value = txtPassword.Text;
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
}
else
{
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
}
#endregion
this.userManager = new UserManager();
this.roleManager = new RoleManager();
this.moduleManager = new ModuleManager();
List<Module> moduleListObject;
List<PMSBL.Entity.User> userListObj;
PMSBL.Entity.Role roleObj;
Module moduleObj;
List<KeyValuePair<string, object>> list;
try
{
string encstr = EncryptDecryptManager.Encrypt(txtPassword.Text.Trim(), true);
userListObj = userManager.UserGetByIdPassword(txtUserName.Text.Trim(), encstr);
PMSBL.Entity.User userObj = null;
if (userListObj != null)
{
if (userListObj.Count == 1)
{
Session[SessionKeys.UserSessionObject] = new SessionObject();
SessionObject.Sess(Session).SiteUser = userListObj.FirstOrDefault();
//get role by roleid
list = new List<KeyValuePair<string, object>>();
list.Add(new KeyValuePair<string, object>("ID", SessionObject.Sess(Session).SiteUser.RoleId));
roleObj = roleManager.RolesGet(list).FirstOrDefault();
FormsAuthentication.SetAuthCookie(SessionObject.Sess(Session).SiteUser.Email, false);
//SecurityManager.AddCookie(SessionObject.Sess(Session).SiteUser.Email, SessionObject.Sess(Session).SiteUser.RoleName);
//get all assigned module to this role
list = new List<KeyValuePair<string, object>>();
list.Add(new KeyValuePair<string, object>("RoleId", SessionObject.Sess(Session).SiteUser.RoleId));
moduleListObject = moduleManager.ModuleGet(list);
if (moduleListObject != null)
SessionObject.Sess(Session).UserModules = moduleListObject;
//get landing page by roleobj
if (roleObj != null)
{
string removeAbbreviation = roleObj.LandingPage;
if (removeAbbreviation.Contains('('))
removeAbbreviation = removeAbbreviation.Substring(0, removeAbbreviation.IndexOf('(') - 1);
list = new List<KeyValuePair<string, object>>();
list.Add(new KeyValuePair<string, object>("ModuleName", removeAbbreviation.Trim()));
list.Add(new KeyValuePair<string, object>("RoleId", roleObj.ID));
List<Module> moduleList = moduleManager.ModuleGet(list);
if (moduleList != null)
{
moduleObj = moduleList.FirstOrDefault();
if (moduleObj != null)
{
if (moduleObj.ModuleUrl != "")
{
if (Common.IsRouting)
Response.Redirect("/" + moduleObj.RouteUrl);
else
Response.Redirect(moduleObj.ModuleUrl);
}
else
Response.Redirect("~/Default.aspx");
}
}
else
Response.Redirect("~/Default.aspx");
}
else
Response.Redirect("~/Default.aspx");
}
else
Response.Redirect("~/AccessDenied.aspx");
}
else
{
Response.Redirect("~/AccessDenied.aspx");
}
}
catch (Exception ex)
{
throw;
}
}