PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/UserInfo.aspx.cs

https://github.com/sirivedula/BEST
C# | 167 lines | 150 code | 17 blank | 0 comment | 14 complexity | 94d7240c7ab6d8594705c830bb6f3478 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Xml.Linq;
  13. using BaliEnterpriseSystems.BestObjects;
  14. using System.Collections.Generic;
  15. namespace BaliEnterpriseSystems
  16. {
  17. public partial class UserInfo : System.Web.UI.Page
  18. {
  19. protected void Page_LoadComplete(object sender, EventArgs e)
  20. {
  21. if (HttpContext.Current.Session["CurrentUser"] == null)
  22. {
  23. Response.Redirect("Logout.aspx");
  24. }
  25. if (! Utils.User.UserRoleByName("Setup - Users").allowView)
  26. {
  27. Response.Write("You do not have view rights for this page.");
  28. return;
  29. }
  30. ltrSubMenu.Text = UtilMenu.SetupSubMenu("userinfo");
  31. string ms = Request.QueryString["ms"];
  32. ltrMScript.Text = Utils.MenuSelectScript(ms);
  33. ltrState.Text = Utils.StateOptions();
  34. if (IsPostBack)
  35. {
  36. BestUser bs = new BestUser();
  37. string isnew = Request.Form["isnew"];
  38. bool cansave = true;
  39. if (string.IsNullOrEmpty(isnew))
  40. {
  41. List<BestField> bparams = new List<BestField>();
  42. BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
  43. guid.fieldValue = Request.Form["guidfield"];
  44. bparams.Add(guid);
  45. if (!string.IsNullOrEmpty(guid.fieldValue))
  46. {
  47. bs.LoadRows("guidfield=?", bparams);
  48. }
  49. else
  50. {
  51. string delguid = Request.Form["deleteguid"];
  52. if (!string.IsNullOrEmpty(delguid))
  53. {
  54. bparams[0].fieldValue = delguid;
  55. bs.LoadRows("guidfield=?", bparams);
  56. bs.CurrentRow.IsDelete = true;
  57. bs.CurrentRow.Save();
  58. }
  59. cansave = false;
  60. }
  61. }
  62. if (cansave)
  63. {
  64. if (!string.IsNullOrEmpty(isnew))
  65. {
  66. bs.userName = Request.Form["g_userName"];
  67. bs.emailId = Request.Form["g_emailId"];
  68. }
  69. if (string.IsNullOrEmpty(bs.userName))
  70. {
  71. ltrValidateMsg.Text = Utils.WarningMessage("User Name is Required.");
  72. cansave = false;
  73. }
  74. if (string.IsNullOrEmpty(bs.emailId))
  75. {
  76. ltrValidateMsg.Text = Utils.WarningMessage("EMail Address is Required.");
  77. cansave = false;
  78. }
  79. if (cansave)
  80. {
  81. bs.firstName = Request.Form["g_firstName"];
  82. bs.lastName = Request.Form["g_lastName"];
  83. bs.middleName = Request.Form["g_middleName"];
  84. bs.address1 = Request.Form["g_address1"];
  85. bs.address2 = Request.Form["g_address2"];
  86. bs.city = Request.Form["g_city"];
  87. bs.state = Request.Form["g_state"];
  88. bs.zip = Request.Form["g_zip"];
  89. bs.cellPhone = Request.Form["g_cellPhone"];
  90. bs.workPhone = Request.Form["g_workPhone"];
  91. bs.homePhone = Request.Form["g_homePhone"];
  92. bs.gender = Request.Form["g_gender"];
  93. bs.Centers = Request.Form["g_Centers"];
  94. bs.userType = Request.Form["g_userType"];
  95. string randPwd = RandomString(8);
  96. bs.password = Utils.GetMD5Hash(randPwd);
  97. bs.passwordExpiration = DateTime.Today.AddDays(3);
  98. if (bs.CurrentRow.Save())
  99. {
  100. Utils.User.emailUtil.Send(bs.emailId, "BLC Login Information", @"<h2>Welcome to Bali Learning Center!</h2><br><h3>Your login information is enclosed.</h3>
  101. <b>Accessing Your Account</b><br>
  102. Step 1:<br>
  103. Click the link below or enter the URL below into your web browser<br>
  104. Address: <a href=""http://best.vasbal.com"">Bali Learning Center Login</a><br><br>
  105. Step 2:<br>
  106. Enter the following user name and temporary password.<br>
  107. User Name: <b>" + bs.userName + @"</b><br>
  108. Password: <b>" + randPwd + @"</b><br><br>
  109. <h3>This temporary password expires in 24 hours.</h3><br><br>
  110. 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>
  111. <br>
  112. <br>
  113. <br>
  114. Thank you,<br>
  115. Bali Learning Center", bs.firstName + " " + bs.lastName);
  116. }
  117. else
  118. {
  119. ltrValidateMsg.Text = Utils.WarningMessage(bs.CurrentRow.lastError);
  120. }
  121. }
  122. }
  123. }
  124. BestGrid bsGrid = new BestGrid();
  125. bsGrid.PageRequest = Page.Request;
  126. bsGrid.Title = "User Information";
  127. bsGrid.GridTable = new BestUser();
  128. bsGrid.whereClause = "usertype not in ('Student', 'Tutor')";
  129. bsGrid.securityPage = "Setup - Users";
  130. bsGrid.AfterAddHTML="<input type=\"button\" id=\"btnReserPwd\" onclick=\"resetPassword();\" value=\"Reset Password\" />";
  131. ltrGrid.Text = bsGrid.ToHTML();
  132. }
  133. private readonly Random _rng = new Random();
  134. private const string _chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()~-_+={[}}|;:<.>,/?";
  135. private string RandomString(int size)
  136. {
  137. char[] buffer = new char[size];
  138. for (int i = 0; i < size; i++)
  139. {
  140. buffer[i] = _chars[_rng.Next(_chars.Length)];
  141. }
  142. return new string(buffer);
  143. }
  144. }
  145. }