william
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # wallet_backend_design express.js + mysql ## DATABASE: #### 資料型態: Primary Key: varchar或是int (用int可以使用自動遞增,缺點是debug不方便) 整數:int 字串:varchar 時間:datetime 非必填的欄位設為可NULL created_time跟updated_time自動生成)(不確定mysql是否可以) #### TABLE: user id,channel,channel_id,email,username,nick_name,created_time,updated_time wallet id,user_id,selected,name,total,title,desc,created_time,updated_time wallet_record id,wallet_id,wallet_record_tag_id,ordinary,name,description,amount,type(吃/交通..),date,created_time,updated_time wallet_record_tag_id id,wallet_id,ordinary,name,type(支出/收入),created_time,updated_time --- ## API: #### 目錄: A.使用者登入登出系統 一. google登入 二. 註冊(需經過google登入後判斷未註冊回到註冊頁) 三. google登入成功且已註冊 B.wallet 一. 使用者選擇超出buffer的月份時,拿該月+-6個月的資料 二. wallet: 二-a.讀取 二-b.新增 二-c.修改 二-d.刪除 三. wallet紀錄: 三-a.讀取 三-b.新增 三-c.修改 三-d.刪除 四. 標籤: 四-a.讀取 四-b.新增 四-c.修改 四-d.刪除 五. 報表 四-a.讀取 六. 使用者設定 六-a.修改暱稱 ### A.使用者登入登出系統 #### [一. google登入]: request: HTTP: GET url: "/user/login/google" SERVER內流程: 1.轉至google登入介面,使用者填google帳密後按確認: 1-a.google登入成功: 使用Google回來的資料查詢資料庫是否已有該使用者紀錄: 使用該使用者email帳號加密後產生使用者id(sha-256固定產生32位元的字串) 用該使用者id判斷是否已存在在資料庫裡 SELECT EXIST(*) FROM user WHERE user_id=? 若有: 製作該用戶token跟jwt(驗證使用者使否過期用) redirect回前端並用url將token傳給前端登入待轉頁(前端收到token後再發一次request拿取該使用者全部資料) 若無: 製作該用戶token redirect回前端並用url將token傳給前端註冊頁 1-b.google登入失敗: redirect回前端登入頁 response: 直接redirect #### [二. 註冊]: request: url: "user/signup" HTTP: POST header: jwt(json web token字串) content-type: "application/json utf-8" body: { user_token: // [一.google登入]會給token nick_name: } SERVER端驗證: 驗證jwt是否過期 驗證session是否有該使用者紀錄 SERVER內流程: 使用使用者email帳號加密後產生使用者id(sha-256固定產生32位元的字串) 利用session取得該使用者的channel跟channel_id 寫入資料庫: INSERT INTO user values(user_id=?,nick_name=?,channel=?,channel_id=?,created_time=?) //幫該使用者新增一個預設錢包 //幫該使用者的預設錢包新增多個預設標籤(吃/交通/...) response: { status:"error"/"success" message:"註冊成功/失敗" data:{ //無 } } #### [三. google登入成功且已註冊,在重新倒回到前端後再發一次request取得完整資料]: request: POST url: "user/data/get" SERVER端驗證: 驗證jwt是否過期 驗證session是否有該使用者紀錄 SERVER內流程: 從資料庫取得該使用者資料 SELECT * FROM user JOIN wallet ON wallet.user_id=user.id JOIN wallet_record ON wallet_record.wallet_id=wallet.id 將取出的資料轉成以下格式 response: { status:"error"/"success" message:"" data:{ user_id: user_name: user_nick_name: selected_wallet_id:"a", wallets:[ "wallet-a":{ wallet_id, wallet_name: selected: //true/false records:[ { record_id:"wallet-a-record-1" wallet_record_tag_id: record_ordinary: record_name: record_description: record_amount: record_type: record_date: record_created_time: }, { record_id:"wallet-a-record-2" wallet_record_tag_id: record_ordinary: record_name: record_description: record_amount: record_type: record_date: record_created_time: }, ] }, "wallet-b":{ wallet_id, wallet_name: selected: //若selected==false則records為空陣列 records:[ ] } ] } } ### B.wallet #### [一.取得給定錢包給定月份+-6個月的record]: reuqest: SERVER端驗證: 驗證jwt是否過期 驗證session是否有該使用者紀錄 SERVER內流程: 從資料庫取得該使用者資料 response: ### SERVER規則: 1.response status code: 200: GET 成功 201: POST 成功 400: 網路問題 500: SERVER問題 2.登入成功只會回傳selected錢包的所有資料 3.一個錢包只會包含 當月+-6個月的資料 4.除了google登入外的API 都有以下規則: 1.使用cookie跟session驗證該使用者的瀏覽器先前曾經google登入成功過,並利用cookie會過期的特性,驗證使用者是否過期 若要再更安全: 2.使用json web token驗證使用者是否過期 ( 登入成功後將會發送一個jwt給前端,存在local storage或vues內 (放在Local Storage的好處:若關掉再重開瀏覽器則不需要再重新登入 且該字串為加密字串毋須擔心資訊安全問題) 每次request的時候將該token字串放到header內 給後端驗證使用者是否過期 ) 5.若使用google登入跟使用FB登入的email是同一個,則視為同一個帳戶(我們使用加密後的email作為Primary Key) 6.每次增刪改紀錄後會需要重新拿該月+-6個月的資料(在同一個requset/response) 7.使用url傳遞變數時一率採用後端加密前端解密 ### 檔案結構: -model -user -user_service -wallet -wallet_service -wallet_record -wallet_record_service -controller -user -wallet -wallet_record -route -user -wallet -wallet_record -middleware index.js ### model結構:

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully