Support to last login feature
This commit is contained in:
		
							parent
							
								
									85b8b7f4e1
								
							
						
					
					
						commit
						f91cbf0fed
					
				
					 5 changed files with 64 additions and 40 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
|  | @ -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
											
										
									
								
							|  | @ -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) | ||||
|  |  | |||
|  | @ -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}} | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue