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

Last Login for admin manage your users
tokarchuk/v1.17
Lunny Xiao 8 years ago committed by GitHub
commit 1b238fe4d5
  1. 2
      conf/locale/locale_en-US.ini
  2. 9
      models/user.go
  3. 80
      modules/bindata/bindata.go
  4. 7
      routers/user/auth.go
  5. 6
      templates/admin/user/list.tmpl

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

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

@ -127,6 +127,13 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
// Clear whatever CSRF has right now, force to generate a new one // Clear whatever CSRF has right now, force to generate a new one
ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubUrl) 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 { if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl) ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
ctx.Redirect(redirectTo) ctx.Redirect(redirectTo)

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

Loading…
Cancel
Save