Home > front end >  Single sign-on (sso)
Single sign-on (sso)

Time:12-11

On a system login system, three conditions here account password write dead, with appropriate changes when

1. The form form submitted

OpenPostWindow () {

Var newWin=window. The open (),
FormStr=' ';
//set the style to hide, before opening a new TAB to jump page, if there are forms of real option, the user will see the form content data
FormStr='& lt; The form style="visibility: hidden;" Method="POST" action=" access address ? Stitching parameters under "& gt; + '
'& lt; Input type="hidden" name="username" value="https://bbs.csdn.net/topics/ account "/& gt; '+' & lt; Input type="hidden" name="password", "
Value="https://bbs.csdn.net/topics/ password [color=# FF0000] [/color ]"/& gt; + '
'& lt;/form> ';

NewWin. Document. Body. InnerHTML=formStr;
NewWin. Document. Forms [0]. Submit ();
Return newWin;
},

2. The same domain name
Axios ({
Headers: {
'deviceCode' : 'A95ZEF1-47 b5 - AC90BF3',
'the content-type' : 'application/x - WWW - form - urlencoded'
},
Method: "post",
TransformRequest: [function (data) {
//to any data conversion processing
Return Qs. Stringify (data)
},
Url: 'address'
Data: {
User_name: 'account',
Pass_word: password md5 encryption,
}
}). Then (res=& gt; {
SessionStorage. SetItem (' token 'res. Data. The data. The token)//save the request token user information
LocalStorage. SetItem (" userName ", res. Data. The data. The user. The user_true_name);
After the success of the landing window. The open (" jump url ")
})
},
3. Cross domain login
Cross domain login first to convert him to the same domain and then cache, write a separate HTML mount to domain name the same server, the current system windo. Open (address) of mount in this HTML to request (HTML is axios request) I after the need to request the account password to send a request to store token, and use it every time after a moderate amount of reference
<script SRC="https://bbs.csdn.net/topics/js/axios.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/js/md5.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/js/qs.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/js/vue.js" & gt; </script>
<script>

Var app=new Vue ({
El: "# app,"
Data () {
Return {

}

},
Methods: {
OpenAxiosWindow () {
Axios. Post (' send the address of the account password, {
User_name: 'account',
Pass_word: hex_md5 (" password ")
}). Then (res=& gt; {
The console. The log (res)
LocalStorage. SetItem (" ms_username, "res. Data. User_true_name);
Enclosing getinfo ()

})

},
Getinfo () {
Axios. Post (' request address). Then (res=& gt; {
The console. The log (' full results')
The console. The log (res)
The console. The log (' res. Data. The user. The user_name)
The console. The log (res) data. User. User_name)
LocalStorage. SetItem (" loginName, "res. Data. User. User_name);
LocalStorage. SetItem (" loginPass ", "admin");
Window. The location. Href='https://bbs.csdn.net/topics/jump after a successful login address;
})
}


},
Mounted () {
},
Created () {
Enclosing openAxiosWindow ()
}
});
</script>

CodePudding user response:

  • Related