Home > front end >  The login
The login

Time:12-02

1. The login view page declared a global variable to store layui module, convenient to call the whole page: var layer;
2. Load layui modules: layui. Use (' layer ', function () {layer=layui. Layer; });
3. Start to write the log in button click event:
3.1. To obtain the form data: var variable name=$(' # form form ID [name="custom data name"] "). The val ();
3.2. Data validation: data judgment is undefined, null...
3.3. Data submission:
3.3.1. Open load layer: loading layer in general web request before open the
Var variable name=layer. The load ();
~ : web application root
Root/: website, go to the port
$.post (" @ Url. Content (" ~/controller/login authentication controller name ") ",
{
A variable name: variable names,
A variable name: variable names,
.
},
3.3.2 rainfall distribution on 10-12. In the front of the network request callback closed loading layer: layer. The close (variable name);
3.4. Refresh the validation images click event
The function () {
click event nameChange validation img element of the SRC attribute switch pictures t parameters: in order to avoid the browser cache picture
$(" # image ID "), prop (" SRC ", "@ Url. Content (" ~/controller/captcha controller name? T=") "+ new Date (). The getTime ());
}
4. Create a new authentication code controller in the controller to generate verification code and verification picture
4.1 generate random string length of 5 as a captcha
String verification code name=ValidCodeUtils. GetRandomCode (5);
4.2 according to the generated captcha string generated verification picture
Byte [] verification picture name=ValidCodeUtils. The CreateImage (captcha);
4.3 the generated verification code strings to the Session
The Session [" authentication code name "]=authentication code name;
4.4 - will verify that the image return to the page
Return the File (image, "image/jpeg");
5. Create a new login to verify the controller name
Prepare the data returned: ReturnJson custom name=new ReturnJson ();
MSG. State=false;//set the default state can be omitted don't write: bool type of data the default value is false
5.1 - check if user input validation code right
5.1.1 - from session for the preservation of captcha string
String sessionValidCode="";
If (Session [" authentication code name "]!=null)
{
SessionValidCode=Session [r]. "authentication code name" ToString ();
}
5.1.2 - validate user input verification code and verification code in the session is whether the same ignore case
Verification code name=captcha name==null? "" : the verification code. The Trim ();
If (sessionValidCode. Equals (authentication code name, StringComparison. InvariantCultureIgnoreCase) | | authentication code name=="")
{the single table linq query method
(from the custom table name in the Model object. The query table
[where custom table name. Value field 1 relational operator [& amp; & amp; custom table name. Field value 2 relational operator]]
[] orderby custom table name. Field
[select custom table name]
[the select new {[attribute name=1] custom table name. Field 1,
[the attribute name=2] custom table name. Field 2,
[the attribute name=3] custom table name. Field 3,
.
}]
[select new class name {1=custom attributes of a class name of the table. Field 1,
Attributes of a class 2=custom table name. Field 2,
.
}]
), Single ();//query a single data, when there is no data or have multiple data triggered when abnormal
SingleOrDefault ();//query a single data, when no data is returned to the default value object (the default value is null); When there are multiple data trigger abnormal
ToList ();//query multiple data and converted to a List
The Count (); How many//query data
5.2 - user authentication data
5.2.1 - for the user to enter the password for AES encryption
String aesPassword=AESEncryptHelper. Encrypt (userPassword)
5.3 handle remember I this function using cookies
Instance cookies: HttpCookie cookie=new HttpCookie (" custom name ");
Save the data to cookies: cookies [" custom name "]=custom name;
The validity of the setting cookies day (quantity) :
Cookies. Expires=DateTime. Now. AddDays (number);
Return the json data format: return json (custom name, JsonRequestBehavior. AllowGet);
  • Related