Skip to content

Commit 1b238fe

Browse files
authored
Merge pull request #121 from joubertredrat/feature-last-login
Last Login for admin manage your users
2 parents c6c840f + f91cbf0 commit 1b238fe

File tree

5 files changed

+64
-40
lines changed

5 files changed

+64
-40
lines changed

conf/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,8 @@ users.activated = Activated
950950
users.admin = Admin
951951
users.repos = Repos
952952
users.created = Created
953+
users.last_login = Last Login
954+
users.never_login = Never Login
953955
users.send_register_notify = Send Registration Notification To User
954956
users.new_success = New account '%s' has been created successfully.
955957
users.edit = Edit

models/user.go

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type User struct {
7575
CreatedUnix int64
7676
Updated time.Time `xorm:"-"`
7777
UpdatedUnix int64
78+
LastLogin time.Time `xorm:"-"`
79+
LastLoginUnix int64
7880

7981
// Remember visibility choice for convenience, true for private
8082
LastRepoVisibility bool
@@ -119,6 +121,11 @@ func (u *User) BeforeUpdate() {
119121
u.UpdatedUnix = time.Now().Unix()
120122
}
121123

124+
// Set time to last login
125+
func (u *User) SetLastLogin() {
126+
u.LastLoginUnix = time.Now().Unix()
127+
}
128+
122129
func (u *User) AfterSet(colName string, _ xorm.Cell) {
123130
switch colName {
124131
case "full_name":
@@ -127,6 +134,8 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
127134
u.Created = time.Unix(u.CreatedUnix, 0).Local()
128135
case "updated_unix":
129136
u.Updated = time.Unix(u.UpdatedUnix, 0).Local()
137+
case "last_login_unix":
138+
u.LastLogin = time.Unix(u.LastLoginUnix, 0).Local()
130139
}
131140
}
132141

modules/bindata/bindata.go

+40-40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

routers/user/auth.go

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
127127
// Clear whatever CSRF has right now, force to generate a new one
128128
ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubUrl)
129129

130+
// Register last login
131+
u.SetLastLogin()
132+
if err := models.UpdateUser(u); err != nil {
133+
ctx.Handle(500, "UpdateUser", err)
134+
return
135+
}
136+
130137
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
131138
ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl)
132139
ctx.Redirect(redirectTo)

templates/admin/user/list.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<th>{{.i18n.Tr "admin.users.admin"}}</th>
2626
<th>{{.i18n.Tr "admin.users.repos"}}</th>
2727
<th>{{.i18n.Tr "admin.users.created"}}</th>
28+
<th>{{.i18n.Tr "admin.users.last_login"}}</th>
2829
<th>{{.i18n.Tr "admin.users.edit"}}</th>
2930
</tr>
3031
</thead>
@@ -38,6 +39,11 @@
3839
<td><i class="fa fa{{if .IsAdmin}}-check{{end}}-square-o"></i></td>
3940
<td>{{.NumRepos}}</td>
4041
<td><span title="{{DateFmtLong .Created}}">{{DateFmtShort .Created }}</span></td>
42+
{{if .LastLoginUnix}}
43+
<td><span title="{{DateFmtLong .LastLogin}}">{{DateFmtShort .LastLogin }}</span></td>
44+
{{else}}
45+
<td><span>{{$.i18n.Tr "admin.users.never_login"}}</span></td>
46+
{{end}}
4147
<td><a href="{{$.Link}}/{{.ID}}"><i class="fa fa-pencil-square-o"></i></a></td>
4248
</tr>
4349
{{end}}

0 commit comments

Comments
 (0)