Skip to content

Commit

Permalink
Merge pull request #121 from joubertredrat/feature-last-login
Browse files Browse the repository at this point in the history
Last Login for admin manage your users
  • Loading branch information
lunny authored Nov 10, 2016
2 parents c6c840f + f91cbf0 commit 1b238fe
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 40 deletions.
2 changes: 2 additions & 0 deletions conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand All @@ -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()
}
}

Expand Down
80 changes: 40 additions & 40 deletions modules/bindata/bindata.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions routers/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions templates/admin/user/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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}}
Expand Down

0 comments on commit 1b238fe

Please sign in to comment.