func AutoSignIn(ctx *context.Context) (bool, error) {
	if !models.HasEngine {
		return false, nil
	}

	uname := ctx.GetCookie(setting.CookieUserName)
	if len(uname) == 0 {
		return false, nil
	}

	isSucceed := false
	defer func() {
		if !isSucceed {
			log.Trace("auto-login cookie cleared: %s", uname)
			ctx.DeleteCookie(setting.CookieUserName)
			ctx.DeleteCookie(setting.CookieRememberName)
		}
	}()

	u, err := models.GetUserByName(uname)
	if err != nil {
		if !models.IsErrUserNotExist(err) {
			return false, fmt.Errorf("GetUserByName: %v", err)
		}
		return false, nil
	}

	if val, ok := ctx.GetSuperSecureCookie(
		base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); !ok || val != u.Name {
		return false, nil
	}

	isSucceed = true

	// Set session IDs
	if err := ctx.Session.Set("uid", u.ID); err != nil {
		return false, err
	}
	if err := ctx.Session.Set("uname", u.Name); err != nil {
		return false, err
	}
	if err := ctx.Session.Release(); err != nil {
		return false, err
	}

	middleware.DeleteCSRFCookie(ctx.Resp)
	return true, nil
}
// AutoSignIn reads cookie and try to auto-login.
AutoSignIn reads cookie and try to auto-login.
// AutoSignIn reads cookie and try to auto - login .
func AutoSignIn(ctx *context.Context) (bool, error) {
	if !models.HasEngine {
		return false, nil
	}
	uname := ctx.GetCookie(setting.CookieUserName)
	if len(uname) == 0 {
		return false, nil
	}
	isSucceed := false
	defer func() {
		if !isSucceed {
			log.Trace("auto-login cookie cleared: %s", uname)
			ctx.DeleteCookie(setting.CookieUserName)
			ctx.DeleteCookie(setting.CookieRememberName)
		}
	}()
	u, err := models.GetUserByName(uname)
	if err != nil {
		if !models.IsErrUserNotExist(err) {
			return false, fmt.Errorf("GetUserByName: %v", err)
		}
		return false, nil
	}
	if val, ok := ctx.GetSuperSecureCookie(
		base.EncodeMD5(u.Rands+u.Passwd), setting.CookieRememberName); !ok || val != u.Name {
		return false, nil
	}
	isSucceed = true
	if err := ctx.Session.Set("uid", u.ID); err != nil {
		return false, err
	}
	if err := ctx.Session.Set("uname", u.Name); err != nil {
		return false, err
	}
	if err := ctx.Session.Release(); err != nil {
		return false, err
	}
	middleware.DeleteCSRFCookie(ctx.Resp)
	return true, nil
}
func AutoSignIn ( ctx * context . Context ) ( bool , error ) { if ! models . HasEngine { return false , nil } uname := ctx . GetCookie ( setting . CookieUserName ) if len ( uname ) == 0 { return false , nil } isSucceed := false defer func ( ) { if ! isSucceed { log . Trace ( " " , uname ) ctx . DeleteCookie ( setting . CookieUserName ) ctx . DeleteCookie ( setting . CookieRememberName ) } } ( ) u , err := models . GetUserByName ( uname ) if err != nil { if ! models . IsErrUserNotExist ( err ) { return false , fmt . Errorf ( " " , err ) } return false , nil } if val , ok := ctx . GetSuperSecureCookie ( base . EncodeMD5 ( u . Rands + u . Passwd ) , setting . CookieRememberName ) ; ! ok || val != u . Name { return false , nil } isSucceed = true if err := ctx . Session . Set ( " " , u . ID ) ; err != nil { return false , err } if err := ctx . Session . Set ( " " , u . Name ) ; err != nil { return false , err } if err := ctx . Session . Release ( ) ; err != nil { return false , err } middleware . DeleteCSRFCookie ( ctx . Resp ) return true , nil }
AutoSignIn reads cookie and try to auto-login.
AutoSignIn reads cookie and try to auto - login .
// Set session IDs