Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Login for admin manage your users #121

Merged
merged 1 commit into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has to start with the function-name, e.g // SetLastLogin sets the time of last login. May sound stupid, but go fmt requires it 😒

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkcsoft Okay, I will provide this

func (u *User) SetLastLogin() {
u.LastLoginUnix = time.Now().Unix()
}

func (u *User) AfterSet(colName string, _ xorm.Cell) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it requires a comment that starts with // AfterSet

Copy link
Contributor Author

@joubertredrat joubertredrat Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkcsoft AfterSet wasn't written by me, then I think that I don't know that this function make. I can take advantage of my commit and put it, but I'll need help to understand this function. Or I can put only // AfterSet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkcsoft can be // AfterSet format data from database for display?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// AfterSet does magic :trollface: (ask @lunny since he knows XORM 🙂 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunny now the ball is with you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @andreynering, comment these should be another PR.

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