PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/????/??????/login.asp

http://masjwzb.googlecode.com/
ASP | 482 lines | 330 code | 64 blank | 88 comment | 5 complexity | d6944e64e7e37d4c7346c4df8d321584 MD5 | raw file
  1. <%@ CodePage="936" LCID="2052" %>
  2. <%
  3. Response.Buffer = EW_RESPONSE_BUFFER
  4. %>
  5. <!--#include file="ewcfg8.asp"-->
  6. <!--#include file="adminsinfo.asp"-->
  7. <!--#include file="aspfn8.asp"-->
  8. <!--#include file="md5.asp"-->
  9. <!--#include file="userfn8.asp"-->
  10. <% Session.Timeout = 20 %>
  11. <%
  12. Response.Expires = 0
  13. Response.ExpiresAbsolute = Now() - 1
  14. Response.AddHeader "pragma", "no-cache"
  15. Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
  16. %>
  17. <%
  18. ' Define page object
  19. Dim login
  20. Set login = New clogin
  21. Set Page = login
  22. ' Page init processing
  23. Call login.Page_Init()
  24. ' Page main processing
  25. Call login.Page_Main()
  26. %>
  27. <!--#include file="header_0.asp"-->
  28. <script language="JavaScript" type="text/javascript">
  29. <!--
  30. // Write your client script here, no need to add script tags.
  31. // To include another .js script, use:
  32. // ew_ClientScriptInclude("my_javascript.js");
  33. //-->
  34. </script>
  35. <script type="text/javascript">
  36. <!--
  37. var login = new ew_Page("login");
  38. // extend page with ValidateForm function
  39. login.ValidateForm = function(fobj)
  40. {
  41. if (!this.ValidateRequired)
  42. return true; // ignore validation
  43. if (!ew_HasValue(fobj.username))
  44. return ew_OnError(this, fobj.username, ewLanguage.Phrase("EnterUid"));
  45. if (!ew_HasValue(fobj.password))
  46. return ew_OnError(this, fobj.password, ewLanguage.Phrase("EnterPwd"));
  47. // Call Form Custom Validate event
  48. if (!this.Form_CustomValidate(fobj)) return false;
  49. return true;
  50. }
  51. // extend page with Form_CustomValidate function
  52. login.Form_CustomValidate =
  53. function(fobj) { // DO NOT CHANGE THIS LINE!
  54. // Your custom validation code here, return false if invalid.
  55. return true;
  56. }
  57. // requires js validation
  58. <% If EW_CLIENT_VALIDATE Then %>
  59. login.ValidateRequired = true;
  60. <% Else %>
  61. login.ValidateRequired = false;
  62. <% End If %>
  63. //-->
  64. </script>
  65. <p class="aspmaker"><b><%= Language.ProjectPhrase("BodyTitle") %></b></p>
  66. <% If EW_DEBUG_ENABLED Then Response.Write login.DebugMsg %>
  67. <% login.ShowMessage %>
  68. <form action="<%= ew_CurrentPage %>" method="post" onsubmit="return login.ValidateForm(this);">
  69. <br/><br/><br/>
  70. <table border="0" cellspacing="0" width="649px" height="430px" align="center" cellpadding="0" style="background-image:url(images/areabg2.jpg);background-repeat:no-Repeat;">
  71. <tr style="height:130px;">
  72. <td>&nbsp;</td>
  73. <td>&nbsp;</td>
  74. </tr>
  75. <tr style="height:30px;">
  76. <td style="padding:20px 0px 0px 50px;color:#ffffff;" align="right"><span class="aspmaker"><%= Language.Phrase("UserName") %> : </span></td>
  77. <td style="padding:20px 0px 0px 0px;"><span class="aspmaker"><input type="text" name="username" id="username" size="20" value="<%= login.sUsername %>"></span></td>
  78. </tr>
  79. <tr style="height:30px;">
  80. <td style="padding:20px 0px 0px 50px;color:#ffffff;" align="right"><span class="aspmaker"><%= Language.Phrase("Password") %> : </span></td>
  81. <td style="padding:20px 0px 0px 0px;"><span class="aspmaker"><input type="password" name="password" id="password" size="20"></span></td>
  82. </tr>
  83. <tr style="height:60px;color:#ffffff;">
  84. <td>&nbsp;</td>
  85. <td><span class="aspmaker">
  86. <input type="radio" name="rememberme" id="rememberme" value="u"<% If login.sLoginType = "u" Then %> checked="checked"<% End If %>><%= Language.Phrase("SaveUserName") %><br>
  87. <input type="radio" name="rememberme" id="rememberme" value=""<% If login.sLoginType = "" Then %> checked="checked"<% End If %>><%= Language.Phrase("AlwaysAsk") %><br>
  88. </span></td>
  89. </tr>
  90. <tr style="height:50px;">
  91. <td colspan="2" align="center"><span class="aspmaker"><input type="submit" name="submit" id="submit" value="<%= ew_BtnCaption(Language.Phrase("Login")) %>"></span><span class="aspmaker">
  92. <a href="register.asp" style="color:white;"><%= Language.Phrase("Register") %></a>&nbsp;&nbsp;&nbsp;&nbsp;
  93. </span></td>
  94. </tr>
  95. <tr>
  96. <td>&nbsp;</td>
  97. <td>&nbsp;</td>
  98. </tr>
  99. </table>
  100. </form>
  101. <br>
  102. <p><span class="aspmaker">
  103. </span></p>
  104. <script language="JavaScript" type="text/javascript">
  105. <!--
  106. // Write your startup script here
  107. // document.write("page loaded");
  108. //-->
  109. </script>
  110. <!--#include file="footer_0.asp"-->
  111. <%
  112. ' Drop page object
  113. Set login = Nothing
  114. %>
  115. <%
  116. ' -----------------------------------------------------------------
  117. ' Page Class
  118. '
  119. Class clogin
  120. ' Page ID
  121. Public Property Get PageID()
  122. PageID = "login"
  123. End Property
  124. ' Page Object Name
  125. Public Property Get PageObjName()
  126. PageObjName = "login"
  127. End Property
  128. ' Page Name
  129. Public Property Get PageName()
  130. PageName = ew_CurrentPage()
  131. End Property
  132. ' Page Url
  133. Public Property Get PageUrl()
  134. PageUrl = ew_CurrentPage() & "?"
  135. End Property
  136. ' Common urls
  137. Dim AddUrl
  138. Dim EditUrl
  139. Dim CopyUrl
  140. Dim DeleteUrl
  141. Dim ViewUrl
  142. Dim ListUrl
  143. ' Export urls
  144. Dim ExportPrintUrl
  145. Dim ExportHtmlUrl
  146. Dim ExportExcelUrl
  147. Dim ExportWordUrl
  148. Dim ExportXmlUrl
  149. Dim ExportCsvUrl
  150. ' Inline urls
  151. Dim InlineAddUrl
  152. Dim InlineCopyUrl
  153. Dim InlineEditUrl
  154. Dim GridAddUrl
  155. Dim GridEditUrl
  156. Dim MultiDeleteUrl
  157. Dim MultiUpdateUrl
  158. ' Debug Message
  159. Dim m_DebugMsg
  160. Public Property Get DebugMsg()
  161. If m_DebugMsg <> "" Then
  162. DebugMsg = "<p>" & m_DebugMsg & "</p>"
  163. Else
  164. DebugMsg = ""
  165. End If
  166. End Property
  167. Public Property Let DebugMsg(v)
  168. If m_DebugMsg <> "" Then ' Append
  169. m_DebugMsg = m_DebugMsg & "<br>" & v
  170. Else
  171. m_DebugMsg = v
  172. End If
  173. End Property
  174. ' Message
  175. Public Property Get Message()
  176. Message = Session(EW_SESSION_MESSAGE)
  177. End Property
  178. Public Property Let Message(v)
  179. If Session(EW_SESSION_MESSAGE) <> "" Then ' Append
  180. Session(EW_SESSION_MESSAGE) = Session(EW_SESSION_MESSAGE) & "<br>" & v
  181. Else
  182. Session(EW_SESSION_MESSAGE) = v
  183. End If
  184. End Property
  185. ' Show Message
  186. Public Sub ShowMessage()
  187. Dim sMessage
  188. sMessage = Message
  189. Call Message_Showing(sMessage)
  190. If sMessage <> "" Then Response.Write "<p><span class=""ewMessage"">" & sMessage & "</span></p>"
  191. Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
  192. End Sub
  193. ' -----------------------
  194. ' Validate Page request
  195. '
  196. Public Function IsPageRequest()
  197. IsPageRequest = True
  198. End Function
  199. ' -----------------------------------------------------------------
  200. ' Class initialize
  201. ' - init objects
  202. ' - open ADO connection
  203. '
  204. Private Sub Class_Initialize()
  205. StartTimer = Timer ' Init start time
  206. ' Initialize language object
  207. Set Language = New cLanguage
  208. ' Initialize table object
  209. Set admins = New cadmins
  210. ' Initialize form object
  211. Set ObjForm = Nothing
  212. ' Intialize page id (for backward compatibility)
  213. EW_PAGE_ID = "login"
  214. ' Open connection to the database
  215. Call ew_Connect()
  216. End Sub
  217. ' -----------------------------------------------------------------
  218. ' Subroutine Page_Init
  219. ' - called before page main
  220. ' - check Security
  221. ' - set up response header
  222. ' - call page load events
  223. '
  224. Sub Page_Init()
  225. Set Security = New cAdvancedSecurity
  226. ' Global page loading event (in userfn7.asp)
  227. Call Page_Loading()
  228. ' Page load event, used in current page
  229. Call Page_Load()
  230. End Sub
  231. ' -----------------------------------------------------------------
  232. ' Class terminate
  233. ' - clean up page object
  234. '
  235. Private Sub Class_Terminate()
  236. Call Page_Terminate("")
  237. End Sub
  238. ' -----------------------------------------------------------------
  239. ' Subroutine Page_Terminate
  240. ' - called when exit page
  241. ' - clean up ADO connection and objects
  242. ' - if url specified, redirect to url
  243. '
  244. Sub Page_Terminate(url)
  245. ' Page unload event, used in current page
  246. Call Page_Unload()
  247. ' Global page unloaded event (in userfn60.asp)
  248. Call Page_Unloaded()
  249. If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
  250. Set Conn = Nothing
  251. Set Security = Nothing
  252. Set ObjForm = Nothing
  253. ' Go to url if specified
  254. Dim sRedirectUrl
  255. sReDirectUrl = url
  256. Call Page_Redirecting(sReDirectUrl)
  257. If sReDirectUrl <> "" Then
  258. If Response.Buffer Then Response.Clear
  259. Response.Redirect sReDirectUrl
  260. End If
  261. End Sub
  262. '
  263. ' Subroutine Page_Terminate (End)
  264. ' ----------------------------------------
  265. Dim sUsername
  266. Dim sLoginType
  267. ' -----------------------------------------------------------------
  268. ' Page main processing
  269. '
  270. Sub Page_Main()
  271. Dim bValidate, bValidPwd
  272. Dim sPassword
  273. Dim sLastUrl
  274. sLastUrl = Security.LastUrl ' Get Last Url
  275. If sLastUrl = "" Then sLastUrl = "default.asp"
  276. If IsLoggingIn() Then
  277. sUsername = Session(EW_SESSION_USER_PROFILE_USER_NAME)
  278. sPassword = Session(EW_SESSION_USER_PROFILE_PASSWORD)
  279. sLoginType = Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE)
  280. bValidPwd = Security.ValidateUser(sUsername, sPassword, False)
  281. If bValidPwd Then
  282. Session(EW_SESSION_USER_PROFILE_USER_NAME) = ""
  283. Session(EW_SESSION_USER_PROFILE_PASSWORD) = ""
  284. Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE) = ""
  285. End If
  286. Else
  287. If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
  288. Call Security.LoadUserLevel() ' Load user level
  289. If Request.Form <> "" Then
  290. ' Setup variables
  291. sUsername = Request.Form("Username")
  292. sPassword = Request.Form("Password")
  293. sLoginType = LCase(Request.Form("rememberme"))
  294. bValidate = ValidateForm(sUsername, sPassword)
  295. If Not bValidate Then
  296. Message = gsFormError
  297. End If
  298. Session(EW_SESSION_USER_PROFILE_USER_NAME) = sUsername ' Save login user name
  299. Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE) = sLoginType ' Save login type
  300. Else
  301. If Security.IsLoggedIn() Then
  302. If Message = "" Then Page_Terminate(sLastUrl) ' Return to last accessed page
  303. End If
  304. bValidate = False
  305. ' Restore settings
  306. sUsername = Request.Cookies(EW_PROJECT_NAME)("username")
  307. If Request.Cookies(EW_PROJECT_NAME)("autologin") = "autologin" Then
  308. sLoginType = "a"
  309. ElseIf Request.Cookies(EW_PROJECT_NAME)("autologin") = "rememberUsername" Then
  310. sLoginType = "u"
  311. Else
  312. sLoginType = ""
  313. End If
  314. End If
  315. bValidPwd = False
  316. If bValidate Then
  317. ' Call logging in event
  318. bValidate = User_LoggingIn(sUsername, sPassword)
  319. If bValidate Then
  320. bValidPwd = Security.ValidateUser(sUsername, sPassword, False) ' Manual login
  321. If Not bValidPwd Then
  322. If Message = "" Then Message = Language.Phrase("InvalidUidPwd") ' Invalid user id/password
  323. End If
  324. Else
  325. If Message = "" Then Message = Language.Phrase("LoginCancelled") ' Login cancelled
  326. End If
  327. End If
  328. End If
  329. If bValidPwd Then
  330. ' Write cookies
  331. If sLoginType = "a" Then ' Auto login
  332. Response.Cookies(EW_PROJECT_NAME)("autologin") = "autologin" ' Set up autologin cookies
  333. Response.Cookies(EW_PROJECT_NAME)("username") = sUsername ' Set up user name cookies
  334. Response.Cookies(EW_PROJECT_NAME)("password") = ew_Encode(TEAencrypt(sPassword, EW_RANDOM_KEY)) ' Set up password cookies
  335. ElseIf sLoginType = "u" Then ' Remember user name
  336. Response.Cookies(EW_PROJECT_NAME)("autologin") = "rememberUsername" ' Set up remember user name cookies
  337. Response.Cookies(EW_PROJECT_NAME)("username") = sUsername ' Set up user name cookies
  338. Else
  339. Response.Cookies(EW_PROJECT_NAME)("autologin") = "" ' Clear autologin cookies
  340. End If
  341. Response.Cookies(EW_PROJECT_NAME).Expires = DateAdd("d", EW_COOKIE_EXPIRY_TIME, Date)
  342. ' Call loggedin event
  343. Call User_LoggedIn(sUsername)
  344. Call ew_WriteAuditTrailOnLogInOut(sUsername, Language.Phrase("AuditTrailLogin"))
  345. Call Page_Terminate(sLastUrl) ' Return to last accessed url
  346. ElseIf sUsername <> "" And sPassword <> "" Then
  347. ' Call user login error event
  348. Call User_LoginError(sUsername, sPassword)
  349. End If
  350. End Sub
  351. ' -----------------------------------------------------------------
  352. ' Validate form
  353. '
  354. Function ValidateForm(usr, pwd)
  355. ' Initialize
  356. gsFormError = ""
  357. ' Check if validation required
  358. If Not EW_SERVER_VALIDATE Then
  359. ValidateForm = True
  360. Exit Function
  361. End If
  362. If usr = "" Then
  363. If gsFormError <> "" Then gsFormError = gsFormError & "<br>"
  364. gsFormError = gsFormError & Language.Phrase("EnterUid")
  365. End If
  366. If pwd = "" Then
  367. If gsFormError <> "" Then gsFormError = gsFormError & "<br>"
  368. gsFormError = gsFormError & Language.Phrase("EnterPwd")
  369. End If
  370. ' Return validate result
  371. ValidateForm = (gsFormError = "")
  372. ' Call Form Custom Validate event
  373. Dim sFormCustomError
  374. sFormCustomError = ""
  375. ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
  376. If sFormCustomError <> "" Then
  377. If gsFormError <> "" Then gsFormError = gsFormError & "<br>"
  378. gsFormError = gsFormError & sFormCustomError
  379. End If
  380. End Function
  381. ' Page Load event
  382. Sub Page_Load()
  383. 'Response.Write "Page Load"
  384. End Sub
  385. ' Page Unload event
  386. Sub Page_Unload()
  387. 'Response.Write "Page Unload"
  388. End Sub
  389. ' Page Redirecting event
  390. Sub Page_Redirecting(url)
  391. 'url = newurl
  392. End Sub
  393. ' Message Showing event
  394. Sub Message_Showing(msg)
  395. 'msg = newmsg
  396. End Sub
  397. ' User Logging In event
  398. Function User_LoggingIn(usr, pwd)
  399. If Not EW_DEBUG_ENABLED Then On Error Resume Next
  400. ' Enter your code here
  401. ' To cancel, set return value to False
  402. User_LoggingIn = True
  403. End Function
  404. ' User Logged In event
  405. Sub User_LoggedIn(usr)
  406. ' Response.Write "User Logged In"
  407. End Sub
  408. ' User Login Error event
  409. Sub User_LoginError(usr, pwd)
  410. ' Response.Write "User Login Error"
  411. End Sub
  412. ' Form Custom Validate event
  413. Function Form_CustomValidate(CustomError)
  414. 'Return error message in CustomError
  415. Form_CustomValidate = True
  416. End Function
  417. End Class
  418. %>