Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
d6680a0b
Unverified
Commit
d6680a0b
authored
May 19, 2022
by
STEVEN
Committed by
GitHub
May 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: seed data only in dev mode (#61)
parent
304df867
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
40 deletions
+15
-40
10001__user.sql
store/seed/10001__user.sql
+6
-4
sqlite.go
store/sqlite.go
+5
-2
signin.less
web/src/less/signin.less
+0
-8
Signin.tsx
web/src/pages/Signin.tsx
+4
-26
No files found.
store/seed/10001__user.sql
View file @
d6680a0b
INSERT
INTO
user
(
`id`
,
`name`
,
`email`
,
`role`
,
`name`
,
`open_id`
,
`password_hash`
)
VALUES
(
101
,
'guest'
,
'guest@example.com'
,
'guest_open_id'
,
'steven@memos.com'
,
'OWNER'
,
'Steven'
,
'steven_open_id'
,
-- raw password: secret
'$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
);
store/sqlite.go
View file @
d6680a0b
...
...
@@ -54,8 +54,11 @@ func (db *DB) Open() (err error) {
if
err
:=
db
.
migrate
();
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to migrate: %w"
,
err
)
}
if
err
:=
db
.
seed
();
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to seed: %w"
,
err
)
// If mode is dev, then seed the database.
if
db
.
mode
==
"dev"
{
if
err
:=
db
.
seed
();
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to seed: %w"
,
err
)
}
}
}
else
{
// If db file exists and mode is dev, we should migrate and seed the database.
...
...
web/src/less/signin.less
View file @
d6680a0b
...
...
@@ -68,14 +68,6 @@
@apply cursor-wait opacity-80;
}
}
> .btn-text {
@apply text-sm;
}
> .split-text {
@apply text-gray-400 mx-2;
}
}
> .tip-text {
...
...
web/src/pages/Signin.tsx
View file @
d6680a0b
...
...
@@ -25,6 +25,10 @@ const Signin: React.FC<Props> = () => {
useEffect
(()
=>
{
api
.
getSystemStatus
().
then
((
status
)
=>
{
setSiteOwner
(
status
.
owner
);
if
(
status
.
profile
.
mode
===
"dev"
)
{
setEmail
(
"steven@memos.com"
);
setPassword
(
"secret"
);
}
pageLoadingState
.
setFinish
();
});
},
[]);
...
...
@@ -105,28 +109,6 @@ const Signin: React.FC<Props> = () => {
actionBtnLoadingState
.
setFinish
();
};
const
handleAutoSigninAsGuestBtnClick
=
async
()
=>
{
if
(
actionBtnLoadingState
.
isLoading
)
{
return
;
}
try
{
actionBtnLoadingState
.
setLoading
();
await
api
.
login
(
"guest@example.com"
,
"secret"
);
const
user
=
await
userService
.
doSignIn
();
if
(
user
)
{
locationService
.
replaceHistory
(
"/"
);
}
else
{
toastHelper
.
error
(
"😟 Login failed"
);
}
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
"😟 "
+
error
.
message
);
}
actionBtnLoadingState
.
setFinish
();
};
return
(
<
div
className=
{
`page-wrapper signin ${pageLoadingState.isLoading ? "hidden" : ""}`
}
>
<
div
className=
"page-container"
>
...
...
@@ -149,10 +131,6 @@ const Signin: React.FC<Props> = () => {
</
div
>
</
div
>
<
div
className=
"action-btns-container"
>
<
button
className=
{
`btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
handleAutoSigninAsGuestBtnClick
}
>
Login as Guest
</
button
>
<
span
className=
"split-text"
>
/
</
span
>
{
siteOwner
?
(
<
button
className=
{
`btn signin-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment