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)
|
email := getStringVal("email", ctx.R)
|
||||||
password := getStringVal("password", ctx.R)
|
password := getStringVal("password", ctx.R)
|
||||||
|
remember := getStringVal("remember", ctx.R) == "on"
|
||||||
|
|
||||||
u, err := cronsun.GetAccountByEmail(email)
|
u, err := cronsun.GetAccountByEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -112,6 +113,14 @@ func (this *Authentication) GetAuthSession(ctx *Context) {
|
||||||
return
|
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.Email = u.Email
|
||||||
ctx.Session.Data["role"] = u.Role
|
ctx.Session.Data["role"] = u.Role
|
||||||
authInfo.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)
|
ctx.Session, err = sessManager.Get(ctx.W, ctx.R)
|
||||||
if ctx.Session != nil {
|
if ctx.Session != nil {
|
||||||
ctx.Todo(func() {
|
ctx.Todo(func() {
|
||||||
|
if ctx.Session.Email == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := sessManager.Store(ctx.Session); err != nil {
|
if err := sessManager.Store(ctx.Session); err != nil {
|
||||||
log.Errorf("Failed to store session: %s.", err.Error())
|
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 {
|
if c == nil {
|
||||||
sess.key = utils.RandString(32, cookieCharacters...)
|
sess.key = utils.RandString(32, cookieCharacters...)
|
||||||
cookie := &http.Cookie{
|
c = &http.Cookie{
|
||||||
Name: this.conf.CookieName,
|
Name: this.conf.CookieName,
|
||||||
Value: sess.key,
|
Value: sess.key,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
@ -78,8 +78,9 @@ func (this *EtcdStore) Get(w http.ResponseWriter, r *http.Request) (sess *Sessio
|
||||||
Secure: false,
|
Secure: false,
|
||||||
MaxAge: this.conf.Expiration,
|
MaxAge: this.conf.Expiration,
|
||||||
}
|
}
|
||||||
http.SetCookie(w, cookie)
|
http.SetCookie(w, c)
|
||||||
r.AddCookie(cookie)
|
r.AddCookie(c)
|
||||||
|
|
||||||
return
|
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>
|
<label>{{$L('password')}}</label>
|
||||||
<input type="password" v-model="password" placeholder:="$L('password')">
|
<input type="password" v-model="password" placeholder:="$L('password')">
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field" ref="remember">
|
||||||
<div class="ui checkbox">
|
<div class="ui checkbox">
|
||||||
<input type="checkbox" v-model="remember" tabindex="0" class="hidden">
|
<input type="checkbox" v-model="remember" tabindex="0" class="hidden">
|
||||||
<label>{{$L('remember me')}}</label>
|
<label>{{$L('remember me')}}</label>
|
||||||
|
@ -39,15 +39,24 @@ export default {
|
||||||
return {
|
return {
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
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: {
|
methods: {
|
||||||
onSubmit () {
|
onSubmit(){
|
||||||
var vm = this;
|
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)=>{
|
onsucceed(200, (resp)=>{
|
||||||
vm.$store.commit('setEmail', resp.email);
|
vm.$store.commit('setEmail', resp.email);
|
||||||
vm.$store.commit('setRole', resp.role);
|
vm.$store.commit('setRole', resp.role);
|
||||||
|
@ -58,7 +67,7 @@ export default {
|
||||||
do();
|
do();
|
||||||
},
|
},
|
||||||
|
|
||||||
getConfig() {
|
getConfig(){
|
||||||
this.$rest.GET('configurations').onsucceed(200, (resp)=>{
|
this.$rest.GET('configurations').onsucceed(200, (resp)=>{
|
||||||
const Config = (Vue, options)=>{
|
const Config = (Vue, options)=>{
|
||||||
Vue.prototype.$appConfig = resp;
|
Vue.prototype.$appConfig = resp;
|
||||||
|
|
Loading…
Reference in New Issue