mirror of https://github.com/shunfei/cronsun
Fixed "Remember me" feature
parent
d855d09f48
commit
0bb794d433
|
@ -91,6 +91,7 @@ func (this *Authentication) GetAuthSession(ctx *Context) {
|
|||
|
||||
email := getStringVal("email", ctx.R)
|
||||
password := getStringVal("password", ctx.R)
|
||||
remember := getStringVal("remember", ctx.R) == "on"
|
||||
|
||||
u, err := cronsun.GetAccountByEmail(email)
|
||||
if err != nil {
|
||||
|
@ -112,6 +113,14 @@ func (this *Authentication) GetAuthSession(ctx *Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !remember {
|
||||
if c, err := ctx.R.Cookie(conf.Config.Web.Session.CookieName); err == nil {
|
||||
c.MaxAge = 0
|
||||
c.Path = "/"
|
||||
http.SetCookie(ctx.W, c)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Session.Email = u.Email
|
||||
ctx.Session.Data["role"] = u.Role
|
||||
authInfo.Role = u.Role
|
||||
|
|
|
@ -83,6 +83,9 @@ func authHandler(needAuth bool) func(*Context) bool {
|
|||
ctx.Session, err = sessManager.Get(ctx.W, ctx.R)
|
||||
if ctx.Session != nil {
|
||||
ctx.Todo(func() {
|
||||
if ctx.Session.Email == "" {
|
||||
return
|
||||
}
|
||||
if err := sessManager.Store(ctx.Session); err != nil {
|
||||
log.Errorf("Failed to store session: %s.", err.Error())
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (this *EtcdStore) Get(w http.ResponseWriter, r *http.Request) (sess *Sessio
|
|||
|
||||
if c == nil {
|
||||
sess.key = utils.RandString(32, cookieCharacters...)
|
||||
cookie := &http.Cookie{
|
||||
c = &http.Cookie{
|
||||
Name: this.conf.CookieName,
|
||||
Value: sess.key,
|
||||
Path: "/",
|
||||
|
@ -78,8 +78,9 @@ func (this *EtcdStore) Get(w http.ResponseWriter, r *http.Request) (sess *Sessio
|
|||
Secure: false,
|
||||
MaxAge: this.conf.Expiration,
|
||||
}
|
||||
http.SetCookie(w, cookie)
|
||||
r.AddCookie(cookie)
|
||||
http.SetCookie(w, c)
|
||||
r.AddCookie(c)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -18,7 +18,7 @@
|
|||
<label>{{$L('password')}}</label>
|
||||
<input type="password" v-model="password" placeholder:="$L('password')">
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field" ref="remember">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" v-model="remember" tabindex="0" class="hidden">
|
||||
<label>{{$L('remember me')}}</label>
|
||||
|
@ -39,15 +39,24 @@ export default {
|
|||
return {
|
||||
email: '',
|
||||
password: '',
|
||||
remember: false
|
||||
remember: ''
|
||||
}
|
||||
},
|
||||
|
||||
mounted: function(){
|
||||
var vm = this;
|
||||
$(this.$refs.remember).find('.checkbox').checkbox({
|
||||
onChange: function(){
|
||||
vm.remember = $(vm.$refs.remember).find('input[type=checkbox]:checked').val();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
methods: {
|
||||
onSubmit () {
|
||||
onSubmit(){
|
||||
var vm = this;
|
||||
|
||||
this.$rest.GET('session?email='+this.email+'&password='+this.password).
|
||||
this.$rest.GET('session?email='+this.email+'&password='+this.password+'&remember='+this.remember).
|
||||
onsucceed(200, (resp)=>{
|
||||
vm.$store.commit('setEmail', resp.email);
|
||||
vm.$store.commit('setRole', resp.role);
|
||||
|
@ -58,7 +67,7 @@ export default {
|
|||
do();
|
||||
},
|
||||
|
||||
getConfig() {
|
||||
getConfig(){
|
||||
this.$rest.GET('configurations').onsucceed(200, (resp)=>{
|
||||
const Config = (Vue, options)=>{
|
||||
Vue.prototype.$appConfig = resp;
|
||||
|
|
Loading…
Reference in New Issue