feat:add user create and login timestamp fields
This commit is contained in:
parent
56b5007379
commit
3c59e83954
@ -7,6 +7,7 @@ import (
|
||||
"one-api/common"
|
||||
"one-api/model"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -80,6 +81,11 @@ func setupLogin(user *model.User, c *gin.Context) {
|
||||
Role: user.Role,
|
||||
Status: user.Status,
|
||||
}
|
||||
user.LastLoginAt = time.Now().Unix()
|
||||
err = user.Update(false)
|
||||
if err != nil {
|
||||
common.SysError(fmt.Sprintf("update user last_login_at err: %s", err.Error()))
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "",
|
||||
"success": true,
|
||||
|
@ -28,6 +28,8 @@ type User struct {
|
||||
Group string `json:"group" gorm:"type:varchar(32);default:'default'"`
|
||||
AffCode string `json:"aff_code" gorm:"type:varchar(32);column:aff_code;uniqueIndex"`
|
||||
InviterId int `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
LastLoginAt int64 `json:"last_login_at"`
|
||||
}
|
||||
|
||||
func GetMaxUserId() int {
|
||||
|
@ -3,15 +3,8 @@ import { Button, Form, Header, Label, Pagination, Segment, Select, Table } from
|
||||
import { API, isAdmin, showError, timestamp2string } from '../helpers';
|
||||
|
||||
import { ITEMS_PER_PAGE } from '../constants';
|
||||
import { renderQuota } from '../helpers/render';
|
||||
import { renderQuota, renderTimestamp } from '../helpers/render';
|
||||
|
||||
function renderTimestamp(timestamp) {
|
||||
return (
|
||||
<>
|
||||
{timestamp2string(timestamp)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const MODE_OPTIONS = [
|
||||
{ key: 'all', text: '全部用户', value: 'all' },
|
||||
|
@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
|
||||
import { API, showError, showSuccess } from '../helpers';
|
||||
|
||||
import { ITEMS_PER_PAGE } from '../constants';
|
||||
import { renderGroup, renderNumber, renderQuota, renderText } from '../helpers/render';
|
||||
import { renderGroup, renderNumber, renderQuota, renderText, renderTimestamp } from '../helpers/render';
|
||||
|
||||
function renderRole(role) {
|
||||
switch (role) {
|
||||
@ -207,6 +207,22 @@ const UsersTable = () => {
|
||||
>
|
||||
状态
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
sortUser('created_at');
|
||||
}}
|
||||
>
|
||||
注册时间
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
sortUser('last_login_at');
|
||||
}}
|
||||
>
|
||||
最后登录
|
||||
</Table.HeaderCell>
|
||||
<Table.HeaderCell>操作</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
@ -242,6 +258,8 @@ const UsersTable = () => {
|
||||
</Table.Cell>
|
||||
<Table.Cell>{renderRole(user.role)}</Table.Cell>
|
||||
<Table.Cell>{renderStatus(user.status)}</Table.Cell>
|
||||
<Table.Cell>{renderTimestamp(user.created_at, true)}</Table.Cell>
|
||||
<Table.Cell>{renderTimestamp(user.last_login_at, true)}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<div>
|
||||
<Button
|
||||
|
@ -1,4 +1,13 @@
|
||||
import { Label } from 'semantic-ui-react';
|
||||
import {timestamp2string} from "./utils";
|
||||
|
||||
export function renderTimestamp(timestamp, zero2emptyStr = false) {
|
||||
return (
|
||||
<>
|
||||
{timestamp2string(timestamp, zero2emptyStr)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function renderText(text, limit) {
|
||||
if (text.length > limit) {
|
||||
|
@ -132,7 +132,10 @@ export function removeTrailingSlash(url) {
|
||||
}
|
||||
}
|
||||
|
||||
export function timestamp2string(timestamp) {
|
||||
export function timestamp2string(timestamp, zero2emptyStr = false) {
|
||||
if (zero2emptyStr && timestamp === 0) {
|
||||
return ''
|
||||
}
|
||||
let date = new Date(timestamp * 1000);
|
||||
let year = date.getFullYear().toString();
|
||||
let month = (date.getMonth() + 1).toString();
|
||||
|
Loading…
Reference in New Issue
Block a user