using framework_business;
using framework_library;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
///
/// Sign Click
///
///
///
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
oSetup _setup = handler.ReturnSetup();
Session["logout"] = null;
encryption encrypt = new encryption("p@l3tt3");
bool userValid = false;
int userType = 0;
string password = txtPassword.Value;
string email = txtEmail.Value.Trim();
string authCode = String.Empty;
foreach (oUser usr in handler.FindLoginUsers(email, password))
{
if (usr.customerCode == _setup.code)
{
userValid = true;
}
else if (usr.customerCode == "EVOL-1" && usr.userType > pNums.UserType.PowerUser.GetHashCode() && usr.userType != (int)pNums.UserType.CustomUser)
{
userValid = true;
}
if (userValid)
{
userType = usr.userType;
usr.dateLoggedOn = DateTime.Now;
PasswordService.ResetLoginAttempts(usr);
handler.UpdateCentralUser(usr);
if (_setup.securePath != String.Empty)
{
Session["user"] = usr;
//setup auth code
authCode = HttpUtility.UrlEncode(encrypt.encryptValue(_setup.code + "|" + usr.recId + "|" + DateTime.Now.ToString("yyyy-MM-dd")));
}
else
{
Session["user"] = usr;
}
break;
}
}
if (userValid)
{
//CVH - 2016-07-27 - Shoulder Practice - Show checklist modal if specific user on successful login
if (_setup.code == "SHOU-1" && ConfigurationManager.AppSettings["MonthEndUser"] != null && ConfigurationManager.AppSettings["MonthEndUser"].ToString().ToUpper() == email.ToUpper())
{
dynamic navigation = this.FindControl("navigation1");
navigation.ReloadControl();
if (BindMonthEndCheckboxListAndShow())
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modChecklist", "ShowChecklistModal();", true);
else
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "closeLogin", "$('#modLogin').modal('hide');", true);
}
//GR -- added custom redirect to patient info page if website user
else if (userType == pNums.UserType.WebsiteUser.GetHashCode() && _setup.code == "SHOU-1")//to do we need to handle better
RedirectFromPanel(_setup.securePath + "/pages/patient~info?auth=" + authCode);
else
{
string redirectpath = String.Empty;
//find secure landing page
if (userType == pNums.UserType.WebsiteUser.GetHashCode())
{
foreach (oCanvas page in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "isActive,isSecureLandingPage", "1,1", "sequence"))
{
redirectpath = page.name.ToLower();
break;
}
}
if (redirectpath != String.Empty)
{
RedirectFromPanel(_setup.securePath + "/pages/" + redirectpath + "?auth=" + authCode);
}
else
{
switch (Page.AppRelativeVirtualPath.ToLower())
{
case "~/default.aspx":
RedirectFromPanel(_setup.securePath + "/home?auth=" + authCode);
break;
case "~/canvas.aspx":
string page = handler.GetRoutedData("canvas-title");
RedirectFromPanel(_setup.securePath + "/pages/" + page + "?auth=" + authCode);
break;
case "~/error.aspx":
RedirectFromPanel(_setup.securePath + "/home?auth=" + authCode);
break;
default:
RedirectFromPanel(_setup.securePath + "/home?auth=" + authCode);
break;
}
}
}
}
else
{
PasswordService.RecordFailedLoginAttempt(email, _setup.code);
pnlResult.Visible = true;
}
}
catch (Exception ex)
{
exception.HandleException("Login:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void lnkForgot_Click(object sender, EventArgs e)
{
pnlLogin.Visible = false;
pnlForgot.Visible = true;
}
protected void lnkBackToLogin_Click(object sender, EventArgs e)
{
pnlLogin.Visible = true;
pnlForgot.Visible = false;
ScriptManager.RegisterStartupScript(this, GetType(), "renderButton", "renderButton();", true);
}
protected void btnReset_Click(object sender, EventArgs e)
{
string encCode = String.Empty;
bool resetValid = false;
try
{
oSetup _setup = handler.ReturnSetup();
foreach (ovUserShared usrShared in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "isActive,isDeactivated,email,customerCode", "1,0," + txtResetEmail.Value + "," + _setup.code, "", "pal_", true))
{
oUser usrReset = PasswordService.LoadUserById(usrShared.recId);
if (usrReset == null)
continue;
resetValid = true;
encryption encReset = new encryption("r3s3t");
usrReset.isReset = true;
usrReset.resetCode = utils.RandomString(6, true);
usrReset.dateUpdated = DateTime.Now;
//update user with reset code and reset status also date updated set as this is used to determine if reset has expirecd
if (handler.UpdateCentralUser(usrReset))
{
//encrypt code for resetting
encCode = HttpUtility.UrlEncode(encReset.encryptValue(usrReset.resetCode));
oEmail email = new oEmail();
string resetbody = String.Empty;
string Subject = String.Empty;
foreach (oTemplate resetTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.OutboundResponse.GetHashCode().ToString()))
{
if (resetTemplate.templateName.ToLower().Contains("reset"))
{
resetbody = resetTemplate.templateContent;
Subject = resetTemplate.templateName;
break;
}
}
//merge internal body with values
resetbody = resetbody.Replace("src=\"/images", "src=\"" + ConfigurationManager.AppSettings["WebAddy"] + "/images");
resetbody = resetbody.Replace("{WebAddress}", ConfigurationManager.AppSettings["WebAddy"]);
resetbody = resetbody.Replace("{encCode}", encCode);
/* CVH 2016-09-13 Use communication email in Company Setup as from email address */
oSetup setup = handler.ReturnSetup();
email.fromAddress = setup.communicationEmail;
email.toAddress = usrReset.email;
email.Body = resetbody;
/* CVH 2016-09-13 Subject shouldn't read "Palette", get from config */
//email.Subject = "Palette - " + Subject;
email.Subject = ConfigurationManager.AppSettings["WebAddy"].Replace("{content}", Subject);
/* CVH 2016-09-13 Set from address display name from Company Setup */
if (communication.SendAnEmail(email, setup.sendingEmailName))
{
lblResultReset.Visible = true;
lblResultReset.Text = "Success: We have sent you further instructions.";
}
}
}
if (!resetValid)
{
lblResultReset.Visible = true;
lblResultReset.Text = "Email address not found.";
}
}
catch (Exception ex)
{
exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
private string GetRedirectPath()
{
pnlResult.Visible = false;
oSetup _setup = handler.ReturnSetup(false);
if (!_setup.isWebsite)
{
return "/home";
}
else
{
return "Admin.aspx";
}
}
private bool BindMonthEndCheckboxListAndShow()
{
bool hide = true;
try
{
//UserControl lblTest = (UserControl)this.FindControl("navigation1");
//if (lblTest == null)
// throw new Exception("lblTest not found.");
//else
// throw new Exception("FOUND");
UpdatePanel upCheck = (UpdatePanel)this.FindControl("upChecklist");
if (upCheck == null)
throw new Exception("upChecklist not found.");
CheckBoxList chkMonthEndChecklist = (CheckBoxList)upCheck.FindControl("chkMonthEndChecklist");
if (chkMonthEndChecklist == null)
throw new Exception("chkMonthEndChecklist not found.");
Label lblMonthEndChecklistHead = (Label)upCheck.FindControl("lblMonthEndChecklistHead");
chkMonthEndChecklist.Items.Clear();
string periodCol = "";
string currentPeriod = System.DateTime.Now.ToString("yyyyMM");
if (lblMonthEndChecklistHead != null)
lblMonthEndChecklistHead.Text = "Month End Checklist - " + System.DateTime.Now.ToString("MMM yyyy");
foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", "MonthEndChecklist"))
{
ArrayList fieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surf.recId.ToString(), "sequence");
if (fieldList == null || fieldList.Count <= 0)
throw new Exception("No fields found for surface Month End Checklist.");
foreach (oSurfaceField field in fieldList)
{
if (field.surfaceFieldDisplay == "Period")
{
periodCol = field.surfaceFieldName;
break;
}
}
if (periodCol == "")
throw new Exception("No Period field found for surface Month End Checklist.");
//get data for current month
DataTable surfaceData = xData.GetSurfaceData(surf.recId);
//loop through fields, add all checkbox types to checkboxlist and determine if checked or not from data
foreach (oSurfaceField field in fieldList)
{
if (field.surfaceFieldTypeId != pNums.FieldType.Checkbox.GetHashCode())
continue;
ListItem chk = new ListItem(field.surfaceFieldDisplay.Replace("_", ","), field.surfaceFieldName);
chk.Attributes.Add("class", "checkbox");
chk.Selected = false;
foreach (DataRow row in surfaceData.Rows)
{
if (row[periodCol].ToString() != currentPeriod)
continue;
foreach (DataColumn col in surfaceData.Columns)
{
if (col.ColumnName == field.surfaceFieldName)
{
if (row[col].ToString() == "1")
chk.Selected = true;
break;
}
}
}
chkMonthEndChecklist.Items.Add(chk);
if (!chk.Selected)
hide = false;
}
}
}
catch (Exception ex)
{
exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
return !hide;
}
private void RedirectFromPanel(string url)
{
string safeUrl = url.Replace("'", "\\'");
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "loginRedirect", "window.location='" + safeUrl + "';", true);
}
}