-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45df0e5
commit 7857763
Showing
16 changed files
with
593 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use server' | ||
|
||
import { MongoClient } from 'mongodb' | ||
import type { UserData } from '@/app/COLL_TYPE' | ||
|
||
// 连接 MongoDB | ||
const client = new MongoClient(process.env.MONGODB_URI!) | ||
const db = client.db('mailbox') | ||
const user = db.collection('user') | ||
|
||
export async function getUser(email: string, password: string): Promise<UserData | string> { | ||
// 验证邮箱和密码 | ||
const auth = await user.findOne({ email, password }, { projection: { _id: 0 } }) | ||
if (!auth) { | ||
return '401' | ||
} else { | ||
return auth as unknown as UserData | ||
} | ||
} | ||
|
||
export async function updateUser(email: string, password: string, field: string, value: string): Promise<string> { | ||
// 验证邮箱和密码 | ||
const auth = await user.findOne({ email, password }, { projection: { role: 1 } }) | ||
if (!auth) { | ||
return '401' | ||
} else if (auth.role !== 'admin' && auth.role !== 'user') { | ||
return '403' | ||
} | ||
// 更新用户 | ||
await user.updateOne({ email, password }, { $set: { [field]: value } }) | ||
return '200' | ||
} |
Oops, something went wrong.