Skip to content

Commit

Permalink
Add last login
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Feb 14, 2024
1 parent 65992a8 commit 04f9f6f
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 33 deletions.
8 changes: 8 additions & 0 deletions web/internal/service/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"github.com/golang-jwt/jwt/v5"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/yoda/web/internal/api"
"github.com/yoda/web/internal/middleware"
"github.com/yoda/web/internal/storage"
Expand All @@ -12,6 +13,7 @@ import (
type IAuthStorage interface {
GetPermissionByUserId(id int32) (*[]string, error)
GetProleByLogin(login string) (*storage.UserProfile, error)
UpdateLastLogin(id int32) error
UserExists(id int32) bool
}

Expand Down Expand Up @@ -54,6 +56,12 @@ func (s *AuthService) CreateToken(login *api.LoginInfo) (string, time.Time, erro
}

func (s *AuthService) CheckUserById(id int32) bool {
go func(id int32) {
err := s.storage.UpdateLastLogin(id)
if err != nil {
logrus.Error("failed to update last login: ", err)
}
}(id)
return s.storage.UserExists(id)
}

Expand Down
4 changes: 4 additions & 0 deletions web/internal/storage/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (s *Storage) GetProleByLogin(login string) (*UserProfile, error) {
return &profile, nil
}

func (s *Storage) UpdateLastLogin(id int32) error {
return s.db.Exec(`update ml.users set last_login = now() where id=?`, id).Error
}

func (s *Storage) UserExists(id int32) bool {
var count int32
s.db.Raw(`select count(1) from ml.users where id=?`, id).Scan(&count)
Expand Down
113 changes: 113 additions & 0 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/react-dom": "latest",
"dayjs": "^1.11.9",
"deep-equal": "^2.2.2",
"material-react-table": "^2.10.0",
"moment": "^2.29.4",
"react": "^17.0.0 || ^18.0.0",
"react-date-range": "^1.4.0",
Expand Down
16 changes: 15 additions & 1 deletion website/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@ export default function Sidebar(this: any) {
}}
onClick={() => closeSidebar()}
/>

<Box sx={{display: 'flex', gap: 1, alignItems: 'center'}}>
<Box
component="span"
sx={{
width: 24,
height: 24,
background: (theme) =>
`linear-gradient(45deg, ${theme.vars.palette.primary.solidBg}, ${theme.vars.palette.primary.solidBg} 30%, ${theme.vars.palette.primary.softBg})`,
borderRadius: '50%',
boxShadow: (theme) => theme.shadow.md,
'--joy-shadowChannel': (theme) =>
theme.vars.palette.primary.mainChannel,
}}
/>
<IconButton
onClick={() => toggleSidebar()}
variant="outlined"
Expand All @@ -130,7 +144,7 @@ export default function Sidebar(this: any) {
>
<MenuIcon/>
</IconButton>
<ColorSchemeToggle sx={{ml: 'auto'}}/>
{/*<ColorSchemeToggle sx={{ml: 'auto'}}/>*/}
</Box>
<Divider/>
<Box
Expand Down
2 changes: 1 addition & 1 deletion website/src/layouts/dictionary/positions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {useController} from "../../../context";

export function DictPositions() {
const {dispatch} = useController()
const [date, setDate] = useState(dayjs().subtract(1, 'day'))
const [date, setDate] = useState(dayjs())
useEffect(() => {
dispatch(SetMenuActive("menu-dict-item1c-id"))
}, []);
Expand Down
35 changes: 12 additions & 23 deletions website/src/layouts/orderByDay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import * as React from 'react';
import {Fragment, useEffect, useState} from 'react';
import { Fragment, useEffect, useState } from 'react';
import Typography from '@mui/joy/Typography';
import Button from '@mui/joy/Button';
import DownloadRoundedIcon from '@mui/icons-material/DownloadRounded';
import Box from '@mui/joy/Box';
import OrderTable from './OrderTable';
import {AdapterDayjs} from '@mui/x-date-pickers/AdapterDayjs';
import JoyDatePicker from 'components/JoyDatePicker';
import {LocalizationProvider} from '@mui/x-date-pickers';

import 'dayjs/locale/ru';
import dayjs from 'dayjs';
import {CustomOrdersService} from 'layouts/orderByDay/customOrderService';
import {SetMenuActive} from "../../context/actions";
import {useController} from "../../context";
import { CustomOrdersService } from 'layouts/orderByDay/customOrderService';
import { SetMenuActive } from "../../context/actions";
import { useController } from "../../context";
import PickerWithJoyField from 'components/PickerWithJoyField';

export function OrderByDay() {
const {dispatch} = useController()
const [date, setDate] = useState(dayjs().subtract(1, 'day'))
const [date, setDate] = useState(dayjs())
const [isLoading, setIsLoading] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -57,21 +55,12 @@ export function OrderByDay() {
justifyContent: 'space-between',
}}
>
<LocalizationProvider
adapterLocale='ru'
dateAdapter={AdapterDayjs}>
<JoyDatePicker
size="sm"
sx={{
width: '150px'
}}
defaultValue={date}
minDate={dayjs(Date.parse('2023-01-01'))}
maxDate={dayjs()}
onChange={(event) => setDate(event ?? date)}
/>
</LocalizationProvider>

<PickerWithJoyField
defaultValue={date}
minDate={dayjs(Date.parse('2023-01-01'))}
maxDate={dayjs()}
onChange={(event) => setDate(event ?? date)}
/>
<Button
color="primary"
startDecorator={<DownloadRoundedIcon/>}
Expand Down
2 changes: 1 addition & 1 deletion website/src/layouts/saleByMonth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useController } from 'context';
import { SetMenuActive } from 'context/actions';

export function SaleByMonth() {
const [date, setDate] = useState(dayjs().subtract(1, 'month'))
const [date, setDate] = useState(dayjs())
const [isLoading, setIsLoading] = useState(false)
const{ dispatch } = useController()

Expand Down
2 changes: 1 addition & 1 deletion website/src/layouts/stock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function Stocks() {
const [sources, setSources] = useState<string[]>(defaultMarketplaces)
const [filter, setFilter] = useState<string | undefined>(undefined)

const [date, setDate] = useState(dayjs().subtract(1, 'day'))
const [date, setDate] = useState(dayjs())

useEffect(() => {
dispatch(SetMenuActive("menu-stocks-id"))
Expand Down
Loading

0 comments on commit 04f9f6f

Please sign in to comment.