2b5b3185859e445a2664d1324dd13acb35467cc4
Integration/Logging-In.md
| ... | ... | @@ -11,4 +11,43 @@ Izenda, out of the box, does not come with a log-in mechanism. However, there va |
| 11 | 11 | * Common ways to deliver authentication from your application are session variables and cookies. Other methods can be used as long as they are able to populate Izenda's variables within the InitializeReporting method. |
| 12 | 12 | * When integrated, common information that we recommend be passed to Izenda includes the User Name, Tenant ID, Admin or Not and Roles. |
| 13 | 13 | * The boolean [RequireLogin](http://wiki.izenda.us/API/CodeSamples/RequireLogin) only asserts that the [CurrentUsername](http://wiki.izenda.us/API/CodeSamples/CurrentUserName) is not null or the Izenda default. When it is one of these, the user will be redirected to whatever location is set in the [LoginUrl](http://wiki.izenda.us/API/CodeSamples/LoginUrl) variable. |
| 14 | -* There is a sanity check within the InitializeReporting function to ensure that initializtion is run once. We recommend putting code that sets the user outside of this so that it is run every page change. This will ensure that the user hasn't changed and they will only see whatever data they are allowed to see. |
|
| ... | ... | \ No newline at end of file |
| 0 | +* There is a sanity check within the InitializeReporting function to ensure that initializtion is run once. We recommend putting code that sets the user outside of this so that it is run every page change. This will ensure that the user hasn't changed and they will only see whatever data they are allowed to see. |
|
| 1 | + |
|
| 2 | +##Example Log-In Logic |
|
| 3 | + |
|
| 4 | +```csharp |
|
| 5 | +bool AuthenticateUser(string userName, string password, out bool isAdmin) { |
|
| 6 | + DataSet ds = AdHocContext.Driver.GetDataSet(AdHocContext.Driver.CreateCommand(string.Format("select 1 from employeeLogin where userName = '{0}' and password = '{1}'",userName,password))); |
|
| 7 | + isAdmin = false; |
|
| 8 | + string validated = ds.Tables[0].Rows[0][0].ToString(); |
|
| 9 | + |
|
| 10 | + if (userName.ToLower() == "admin" || userName.ToLower() == "administrator") |
|
| 11 | + isAdmin = true; |
|
| 12 | + |
|
| 13 | + if (validated.Equals("1")) |
|
| 14 | + return true; |
|
| 15 | + else |
|
| 16 | + return false; |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + void Button1_Click(object sender, EventArgs args) { |
|
| 20 | + try{ |
|
| 21 | + loginValidator.IsValid = true; |
|
| 22 | + bool isAdmin; |
|
| 23 | + if (AuthenticateUser(userNameTextbox.Text, userPassword.Value, out isAdmin)) { |
|
| 24 | + HttpContext.Current.Session["UserName"] = userNameTextbox.Text; |
|
| 25 | + if (isAdmin) |
|
| 26 | + HttpContext.Current.Session["Role"] = "Administrator"; |
|
| 27 | + else |
|
| 28 | + HttpContext.Current.Session["Role"] = "RegularUser"; |
|
| 29 | + FormsAuthentication.RedirectFromLoginPage(userNameTextbox.Text, false); |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + loginValidator.IsValid = false; |
|
| 33 | + } |
|
| 34 | + catch(IndexOutOfRangeException e) |
|
| 35 | + { |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | +``` |
|
| ... | ... | \ No newline at end of file |