PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/TutorUsers.aspx.cs

https://github.com/sirivedula/BEST
C# | 196 lines | 182 code | 12 blank | 2 comment | 17 complexity | 0d2902f76acc9de8b930d3ccb90818f6 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using BaliEnterpriseSystems.BestObjects;
  8. using System.Text;
  9. namespace BaliEnterpriseSystems
  10. {
  11. public partial class TutorUsers : System.Web.UI.Page
  12. {
  13. protected void Page_LoadComplete(object sender, EventArgs e)
  14. {
  15. if (HttpContext.Current.Session["CurrentUser"] == null)
  16. {
  17. Response.Redirect("Logout.aspx");
  18. }
  19. ltrSubMenu.Text = UtilMenu.TutorMenu("tutorusers");
  20. if (!Utils.User.UserRoleByName("Tutor - Users").allowView)
  21. {
  22. ltrGrid.Text = "You do not have rights to view.";
  23. return;
  24. }
  25. string ms = Request.QueryString["ms"];
  26. this.ltrMScript.Text = Utils.MenuSelectScript(ms);
  27. string saveClicked = Request.Form["SaveClicked"] ?? "";
  28. if (IsPostBack && saveClicked.Equals("1"))
  29. {
  30. BestField fld = new BestField() { fieldName = "guidfield", paramOledbType = System.Data.OleDb.OleDbType.Guid, fieldType = "System.Guid" };
  31. List<BestField> bparam = new List<BestField>();
  32. string delguid = Request.Form["deleteguid"];
  33. if (!string.IsNullOrEmpty(delguid))
  34. {
  35. BestUser bsduser = new BestUser();
  36. fld.fieldValue = delguid;
  37. bparam.Add(fld);
  38. bsduser.LoadRows("guidfield=?", bparam);
  39. bsduser.CurrentRow.IsDelete = true;
  40. if (!bsduser.CurrentRow.Save())
  41. {
  42. ltrValidateMsg.Text = Utils.WarningMessage(bsduser.CurrentRow.lastError);
  43. }
  44. }
  45. else
  46. {
  47. string tutorGud = Request.Form["tutorTag0"];
  48. if (!string.IsNullOrEmpty(tutorGud))
  49. {
  50. fld.fieldValue = tutorGud;
  51. bparam.Add(fld);
  52. BestTutors bstutor = new BestTutors();
  53. bstutor.LoadRows("guidfield=?", bparam);
  54. if (!bstutor.CurrentRow.IsNew)
  55. {
  56. if (string.IsNullOrEmpty(bstutor.emailId))
  57. {
  58. ltrValidateMsg.Text = Utils.WarningMessage("Tutor E-Mail Address is Required.");
  59. }
  60. else
  61. {
  62. BestUser bstuser = new BestUser();
  63. bstuser.userName = bstutor.emailId;
  64. bstuser.firstName = bstutor.firstName;
  65. bstuser.lastName = bstutor.lastName;
  66. bstuser.address1 = bstutor.address1;
  67. bstuser.address2 = bstutor.address2;
  68. bstuser.city = bstutor.city;
  69. bstuser.state = bstutor.state;
  70. bstuser.zip = bstutor.zip;
  71. bstuser.cellPhone = bstutor.cellPhone;
  72. bstuser.workPhone = bstutor.workPhone;
  73. bstuser.homePhone = bstutor.homePhone;
  74. bstuser.tutorGuid = bstutor.guidfield;
  75. bstuser.Centers = bstutor.CenterId;
  76. bstuser.emailId = bstutor.emailId;
  77. bstuser.userType = "Tutor";
  78. string randPwd = RandomString(8);
  79. bstuser.password = Utils.GetMD5Hash(randPwd);
  80. bstuser.passwordExpiration = DateTime.Today.AddDays(3);
  81. if (bstuser.CurrentRow.Save())
  82. {
  83. Utils.User.emailUtil.Send(bstuser.emailId, "BLC Login Information", @"<h2>Welcome to Bali Learning Center!</h2><br><h3>Your login information is enclosed.</h3>
  84. <b>Accessing Your Account</b><br>
  85. Step 1:<br>
  86. Click the link below or enter the URL below into your web browser<br>
  87. Address: <a href=""http://best.vasbal.com"">Bali Learning Center Login</a><br><br>
  88. Step 2:<br>
  89. Enter the following user name and temporary password.<br>
  90. User Name: <b>" + bstuser.userName + @"</b><br>
  91. Password: <b>" + randPwd + @"</b><br><br>
  92. <h3>This temporary password expires in 24 hours.</h3><br><br>
  93. You will be prompted to change your user name and password during your initial log in as well as answer a few security related questions. <br>
  94. <br>
  95. <br>
  96. <br>
  97. Thank you,<br>
  98. Bali Learning Center", bstuser.firstName + " " + bstuser.lastName);
  99. /* Create Tutor - Personal Role */
  100. List<BestField> bparams = new List<BestField>();
  101. BestField paramUName = new BestField() { fieldName = "username", fieldSize = 80, fieldType = "System.String", paramOledbType = System.Data.OleDb.OleDbType.VarChar, displayField = false };
  102. paramUName.fieldValue = bstuser.userName;
  103. BestField service = new BestField() { fieldName = "service", fieldSize = 80, fieldType = "System.String", paramOledbType = System.Data.OleDb.OleDbType.VarChar, displayField = false };
  104. bparams.Add(paramUName);
  105. bparams.Add(service);
  106. string[] aryRoles = { "3.Tutors", "Tutor - Personal", "Tutor - Planner" };
  107. for (int i = 0; i < aryRoles.Length; i++)
  108. {
  109. UserRoles urole = new UserRoles();
  110. bparams[1].fieldValue = aryRoles[i];
  111. urole.LoadRows("username = ? and service=?", bparams);
  112. if (urole.TableRows.Count == 0)
  113. {
  114. urole.Service = aryRoles[i];
  115. urole.UserName = bstuser.userName;
  116. urole.allowView = "1";
  117. urole.CurrentRow.Save();
  118. }
  119. }
  120. }
  121. else
  122. {
  123. ltrValidateMsg.Text = Utils.WarningMessage( bstuser.CurrentRow.lastError);
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130. BestGrid bsGrid = new BestGrid();
  131. bsGrid.PageRequest = Page.Request;
  132. bsGrid.Title = "Tutor Users";
  133. bsGrid.securityPage = "Tutor - Users";
  134. BestUser bsuser = new BestUser();
  135. bsuser.overrideAdd = Utils.User.UserRoleByName("Tutor - Users").allowAdd;
  136. bsuser.overrideDelete = Utils.User.UserRoleByName("Tutor - Users").allowDelete;
  137. bsuser.overrideEdit = false;
  138. bsuser.TableFields["address1"].displayField = false;
  139. bsuser.TableFields["address2"].displayField = false;
  140. bsuser.TableFields["city"].displayField = false;
  141. bsuser.TableFields["zip"].displayField = false;
  142. bsuser.TableFields["state"].displayField = false;
  143. bsuser.TableFields["Centers"].displayField = false;
  144. bsGrid.GridTable = bsuser;
  145. bsGrid.whereClause = "usertype in ('Tutor')";
  146. ltrGrid.Text = bsGrid.ToHTML();
  147. /* Auto Tutors */
  148. StringBuilder sb = new StringBuilder();
  149. string autoSample = "{value:\"[paramValue]\", label:[paramLabel]}";
  150. sb.AppendLine("<script type=\"text/javascript\">");
  151. sb.AppendLine("autoTutors = [");
  152. BestTutors bstd = new BestTutors();
  153. bstd.LoadRows();
  154. for (int s = 0; s < bstd.TableRows.Count; s++)
  155. {
  156. string result = autoSample;
  157. result = result.Replace("[paramValue]", bstd.TableRows[s].Fields["guidfield"].fieldValue);
  158. result = result.Replace("[paramLabel]", Utils.EnquoteJS((bstd.TableRows[s].Fields["firstName"].fieldValue ?? "") + " " +
  159. (bstd.TableRows[s].Fields["lastName"].fieldValue ?? "")));
  160. sb.Append(result);
  161. if (s < bstd.TableRows.Count - 1) sb.AppendLine(",");
  162. }
  163. sb.AppendLine("];");
  164. sb.AppendLine("</script>");
  165. this.ltrScript.Text = sb.ToString();
  166. }
  167. private readonly Random _rng = new Random();
  168. private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()~-_+={[}}|;:<.>,/?";
  169. private string RandomString(int size)
  170. {
  171. char[] buffer = new char[size];
  172. for (int i = 0; i < size; i++)
  173. {
  174. buffer[i] = _chars[_rng.Next(_chars.Length)];
  175. }
  176. return new string(buffer);
  177. }
  178. }
  179. }