0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 23:33:15 -05:00

Merge pull request #121 from joubertredrat/feature-last-login

Last Login for admin manage your users
This commit is contained in:
Lunny Xiao 2016-11-10 17:20:55 +08:00 committed by GitHub
commit 1b238fe4d5
5 changed files with 64 additions and 40 deletions

View file

@ -950,6 +950,8 @@ users.activated = Activated
users.admin = Admin
users.repos = Repos
users.created = Created
users.last_login = Last Login
users.never_login = Never Login
users.send_register_notify = Send Registration Notification To User
users.new_success = New account '%s' has been created successfully.
users.edit = Edit

View file

@ -75,6 +75,8 @@ type User struct {
CreatedUnix int64
Updated time.Time `xorm:"-"`
UpdatedUnix int64
LastLogin time.Time `xorm:"-"`
LastLoginUnix int64
// Remember visibility choice for convenience, true for private
LastRepoVisibility bool
@ -119,6 +121,11 @@ func (u *User) BeforeUpdate() {
u.UpdatedUnix = time.Now().Unix()
}
// Set time to last login
func (u *User) SetLastLogin() {
u.LastLoginUnix = time.Now().Unix()
}
func (u *User) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "full_name":
@ -127,6 +134,8 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
u.Created = time.Unix(u.CreatedUnix, 0).Local()
case "updated_unix":
u.Updated = time.Unix(u.UpdatedUnix, 0).Local()
case "last_login_unix":
u.LastLogin = time.Unix(u.LastLoginUnix, 0).Local()
}
}

File diff suppressed because one or more lines are too long

View file

@ -127,6 +127,13 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
// Clear whatever CSRF has right now, force to generate a new one
ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubUrl)
// Register last login
u.SetLastLogin()
if err := models.UpdateUser(u); err != nil {
ctx.Handle(500, "UpdateUser", err)
return
}
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
ctx.Redirect(redirectTo)

View file

@ -25,6 +25,7 @@
<th>{{.i18n.Tr "admin.users.admin"}}</th>
<th>{{.i18n.Tr "admin.users.repos"}}</th>
<th>{{.i18n.Tr "admin.users.created"}}</th>
<th>{{.i18n.Tr "admin.users.last_login"}}</th>
<th>{{.i18n.Tr "admin.users.edit"}}</th>
</tr>
</thead>
@ -38,6 +39,11 @@
<td><i class="fa fa{{if .IsAdmin}}-check{{end}}-square-o"></i></td>
<td>{{.NumRepos}}</td>
<td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created }}</span></td>
{{if .LastLoginUnix}}
<td><span title="{{DateFmtLong .LastLogin}}">{{DateFmtShort .LastLogin }}</span></td>
{{else}}
<td><span>{{$.i18n.Tr "admin.users.never_login"}}</span></td>
{{end}}
<td><a href="{{$.Link}}/{{.ID}}"><i class="fa fa-pencil-square-o"></i></a></td>
</tr>
{{end}}