home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / vbasic / ProcessNewAcct.asp < prev    next >
Text File  |  2003-09-17  |  6KB  |  189 lines

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <!-- METADATA 
  4.    TYPE="TypeLib" 
  5.    FILE="C:\Program Files\Common Files\System\ADO\msado21.tlb" 
  6. -->
  7. <!--#include file="DatabaseConnect.asp"-->
  8. <html>
  9. <body>
  10. <%
  11.     Dim objRS            
  12.     Dim sSQL
  13.     Dim objRSTeacher        'For Teacher Record info
  14.     Dim Mailer    
  15.     'Check for a valid email address before creating the account
  16.     If Not IsValidEmail(Request.Form("email")) Then
  17.         Response.Redirect "error.asp?error=bademail"
  18.     ElseIf Trim(Request.Form("Password")) = "" Then
  19.         Response.Redirect "error.asp?error=badpassword"
  20.     ElseIf Trim(Request.Form("Last")) = "" Or Trim(Request.Form("First")) = "" Then
  21.         Response.Redirect "error.asp?error=badname"
  22.     ElseIf Not IsAlpha(Trim(Request.Form("Last"))) Or Not IsAlpha(Trim(Request.Form("First"))) Then
  23.         Response.Redirect "error.asp?error=badname"
  24.     End If
  25.  
  26.     sSQL = "SELECT * From Students Where email = '" & Request.Form("email") & "'"
  27.     Set objRS = Server.CreateObject("ADODB.Recordset")
  28.     objRS.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  29.     'Make sure we don't add a duplication account (email MUST be unique)
  30.     If Not (objRS.EOF And objRS.BOF) Then 
  31.         objRS.Close
  32.         Set objRS = Nothing
  33.         objConn.Close
  34.         Set objConn = Nothing
  35.         Session("AcctName") = Request.Form("email")
  36.         Response.Redirect "error.asp?error=dupacct"
  37.     Else    
  38.         objRS.Close
  39.         objRS.Open "Students", objConn, adOpenDynamic, adLockOptimistic, adCmdTable
  40.         objRS.AddNew    
  41.     objRS("name") = Request.Form("Last") & ", " & Request.Form("First")
  42.     objRS("classtype") = Request.Form("CIS40or41")
  43.     objRS("teacher") = Request.Form("Teacher")
  44.     objRS("meetday") = Request.Form("MeetDay")
  45.     objRS("email") = Request.Form("Email")
  46.     objRS("password") = Request.Form("Password")
  47.     objRS("lastlogin") = "Never Logged In"
  48.     objRS("active") = False
  49.     objRS("created") = CStr(Date)
  50.     objRS("security") = vbStudent        'Student access by default
  51.         'Access the Teacher's record so we can get the teacher's email
  52.         sSQL = "SELECT * From Students Where Name = '" & objRS("teacher") & "'"
  53.         Set objRSTeacher = Server.CreateObject("ADODB.Recordset")
  54.         objRSTeacher.Open sSQL, objConn, adOpenDynamic, adLockOptimistic, adCmdText
  55.         objRS("teacheremail") = objRSTeacher("email")
  56.         objRSTeacher.Close
  57.         Set objRSTeacher = Nothing
  58.         'Email the new account info to the Student
  59.         Set Mailer = Server.CreateObject("SoftArtisans.SMTPMail")
  60.         Mailer.FromName = "Guy Campbell"
  61.         Mailer.FromAddress = "gcampbell@moorparkcollege.edu"
  62.         Mailer.organization = "Visual Basic - Moorpark College"
  63.         Mailer.Subject = "Moorpark College -- Visual Basic Student Account Confirmation"
  64.         Mailer.smtplog = "C:\mysmtplog.txt"
  65.         Mailer.live = True
  66.         Mailer.RemoteHost = "sunny.moorpark.cc.ca.us"
  67.         Mailer.Priority = 3        
  68.         Mailer.addrecipient Request.Form("First") & " " & Request.Form("Last"), Request.Form("Email")
  69.         Mailer.bodytext = "Your Visual Basic Account Information has been saved. " & vbCRLF _
  70.                 & vbCRLF _
  71.                 & "Name: " & objRS("name") & vbCRLF _
  72.                 & "EMail: " & objRS("email") & vbCRLF _
  73.                 & "Password: " & objRS("password") & vbCRLF _
  74.                 & "Class: " & objRS("classtype") & vbCRLF _
  75.                 & "Current Status: Disabled" & vbCRLF & vbCRLF _                
  76.                 & "Important:  All information is case sensitive." & vbCRLF & vbCRLF _
  77.                 & "Note: Your Account will be activated within a few days." & vbCRLF _                
  78.                 & "At that time an email will be sent to you to confirm" & vbCRLF _
  79.                 & "that your account has been activated." & vbCRLF  & vbCRLF _
  80.                 & "Thank You, " & vbCRLF & vbCRLF & "Guy Campbell" & vbCRLF & "gcampbell@moorparkcollege.edu"
  81.         Mailer.SendMail                        
  82.         Mailer.ClearRecipients
  83.     End If
  84. %>
  85.  
  86. <P><B> New Visual Basic Student Account Created</B></P>
  87. Account Information Stored:
  88. Name: <%=objRS("name")%><BR>
  89. Class: <%=objRS("classtype")%> on 
  90.  
  91. <% 
  92.     Select Case objRS("meetday")        
  93.         Case "MonWed"
  94.         %>
  95.             Mondays and Wednesdays during the day.
  96.         <%
  97.         Case "TueThur"
  98.         %>
  99.             Tuesdays and Thursdays during the day.
  100.         <%
  101.         Case "Saturday"
  102.         %>
  103.             Saturdays during the day.
  104.         <%
  105.         Case "TueNite"
  106.         %>
  107.             Tuesday evenings.
  108.         <%
  109.         Case "WedNite"
  110.         %>
  111.             Wednesday evenings.
  112.         <%
  113.         Case "ThurNite"
  114.         %>
  115.             Thursday evenings.
  116.         <%
  117.         Case "FriNite"
  118.         %>
  119.             Friday evenings.
  120.         <%
  121.         Case Else
  122.             'Nothing
  123.     End Select
  124. %><BR>
  125.  
  126. Email: <%=objRS("email")%><BR>
  127. Password: <%=objRS("password")%><BR>
  128. <HR>
  129. Please print this page, or write this information down for future reference.<BR>
  130. An email with the above information has been sent to: <%= " " & objRS("email")%><BR>
  131. Important: When your account is activated, an email telling you so will be<BR> 
  132. sent to the above email address (usually within a few days).
  133. <HR>
  134. <INPUT TYPE="Button" VALUE="Finished" onClick="document.location='default.asp';"> 
  135.  
  136. <%
  137.     objRS.Update
  138.     objRS.Close
  139.     Set objRS = Nothing
  140.     objConn.Close
  141.     Set objConn = Nothing
  142. %>
  143.  
  144. <%
  145. 'Returns True if an email address is valid
  146. Function IsValidEmail(strEmail)
  147.     Dim bIsValid
  148.     bIsValid = True
  149.     
  150.     If Len(strEmail) < 5 Then
  151.         bIsValid = False
  152.     Else
  153.         If Instr(1, strEmail, " ") <> 0 Then
  154.             bIsValid = False
  155.         Else
  156.             If InStr(1, strEmail, "@", 1) < 2 Then
  157.                 bIsValid = False
  158.             Else
  159.                 If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
  160.                     bIsValid = False
  161.                 End If
  162.             End If
  163.         End If
  164.     End If
  165.  
  166.     IsValidEmail = bIsValid
  167. End Function
  168.  
  169. 'Returns True if a Name contains only A-Z or a-z characters
  170. Function IsAlpha(strName)
  171.     Dim bIsAlpha
  172.     Dim strChar
  173.     Dim i
  174.     bIsAlpha = True
  175.     'Weed out names that don't use ONLY A-Z or a-z
  176.     For i = 1 to Len(strName)
  177.         strChar = Asc(Mid(strName, i, 1))
  178.         If (strChar < 65 Or strChar > 122) Or _        
  179.            (strChar > 90 And strChar < 97) Then        
  180.           bIsAlpha = False
  181.         End If
  182.     Next
  183.     IsAlpha = bIsAlpha
  184. End Function
  185. %>
  186. </body>
  187. </html>
  188.  
  189.