Fosi Fossil Service
Small teams. Open source. Built on Fossil.

IaC / SwiftFlow

High-performance WMS with wave picking, smart routing, and real-time inventory visibility.

Public | Owner: IaC | Default branch: trunk | Last update: 2026-10-23 14:37

Artifact 27da4e7c0d09d3f5c27e737de02720f3a3e23a68f94d125ce1c9ddee1378583e:


import { useState, type FormEvent } from 'react'
import { api } from '../api'
import { useSession } from '../session'
import { Banner, Field, Page } from '../ui'

export function Account() {
  const { user } = useSession()
  const [oldPassword, setOldPassword] = useState('')
  const [newPassword, setNewPassword] = useState('')
  const [error, setError] = useState('')
  const [ok, setOk] = useState('')

  async function onSubmit(event: FormEvent) {
    event.preventDefault()
    setError('')
    setOk('')
    try {
      await api('/api/auth/password', {
        method: 'POST',
        body: JSON.stringify({ old_password: oldPassword, new_password: newPassword }),
      })
      setOldPassword('')
      setNewPassword('')
      setOk('密码已修改,其他终端的登录已失效')
    } catch (err) {
      setError(err instanceof Error ? err.message : '修改失败')
    }
  }

  return (
    <Page title="账号">
      <div className="cards">
        <div className="card">
          <span>姓名</span>
          <strong>{user?.display_name}</strong>
        </div>
        <div className="card">
          <span>账号</span>
          <strong>{user?.username}</strong>
        </div>
        <div className="card">
          <span>角色</span>
          <strong>{user?.roles.join('、')}</strong>
        </div>
        <div className="card">
          <span>本次登录到期</span>
          <strong>{user?.expires_at}</strong>
        </div>
      </div>
      <form className="panel" onSubmit={onSubmit}>
        <h2>修改密码</h2>
        <Banner kind="error" text={error} />
        <Banner kind="ok" text={ok} />
        <Field label="原密码">
          <input
            type="password"
            value={oldPassword}
            onChange={(event) => setOldPassword(event.target.value)}
          />
        </Field>
        <Field label="新密码(至少 8 位)">
          <input
            type="password"
            value={newPassword}
            onChange={(event) => setNewPassword(event.target.value)}
          />
        </Field>
        <button type="submit" disabled={newPassword.length < 8 || !oldPassword}>
          保存新密码
        </button>
      </form>
    </Page>
  )
}

Clone

You can clone this repository with the following command:

fossil clone https://fosi.dev/IaC/SwiftFlow

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.