From 65eee22099ad8d1529f895772b31282280a624cd Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 14 Feb 2021 21:21:42 +0800 Subject: [PATCH] Check user under org. --- controllers/auth.go | 6 ++++-- main.go | 4 +--- object/check.go | 8 ++++---- object/user.go | 9 +++++---- web/src/App.js | 2 +- web/src/UserEditPage.js | 18 +++++++++++++++++ web/src/UserListPage.js | 39 +++++++++++++++++++++--------------- web/src/auth/AuthBackend.js | 4 ++-- web/src/auth/AuthCallback.js | 6 +++--- web/src/auth/Face.js | 2 +- web/src/auth/Provider.js | 4 ++-- 11 files changed, 64 insertions(+), 38 deletions(-) diff --git a/controllers/auth.go b/controllers/auth.go index 4b067a2d..4b82d575 100644 --- a/controllers/auth.go +++ b/controllers/auth.go @@ -42,12 +42,14 @@ var githubOauthConfig = &oauth2.Config{ } func (c *ApiController) AuthLogin() { + applicationName := c.Input().Get("application") providerName := c.Input().Get("provider") code := c.Input().Get("code") state := c.Input().Get("state") method := c.Input().Get("method") RedirectURL := c.Input().Get("redirect_url") + application := object.GetApplication(fmt.Sprintf("admin/%s", applicationName)) provider := object.GetProvider(fmt.Sprintf("admin/%s", providerName)) githubOauthConfig.ClientID = provider.ClientId githubOauthConfig.ClientSecret = provider.ClientSecret @@ -132,7 +134,7 @@ func (c *ApiController) AuthLogin() { wg.Wait() if method == "signup" { - userId := object.HasGithub(tempUserAccount.Login) + userId := object.HasGithub(application, tempUserAccount.Login) if userId != "" { //if len(object.GetMemberAvatar(userId)) == 0 { // avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId) @@ -142,7 +144,7 @@ func (c *ApiController) AuthLogin() { util.LogInfo(c.Ctx, "API: [%s] signed in", userId) res.IsSignedUp = true } else { - if userId := object.HasMail(res.Email); userId != "" { + if userId := object.HasMail(application, res.Email); userId != "" { c.SetSessionUser(userId) util.LogInfo(c.Ctx, "API: [%s] signed in", userId) res.IsSignedUp = true diff --git a/main.go b/main.go index 7b673b3e..84e48b46 100644 --- a/main.go +++ b/main.go @@ -15,8 +15,6 @@ package main import ( - "net/http" - "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/cors" "github.com/casdoor/casdoor/controllers" @@ -47,7 +45,7 @@ func main() { beego.BConfig.WebConfig.Session.SessionProvider="file" beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp" beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365 - beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode + //beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode beego.Run() } diff --git a/object/check.go b/object/check.go index 57f56336..b97f55ad 100644 --- a/object/check.go +++ b/object/check.go @@ -28,16 +28,16 @@ func (user *User) getId() string { return fmt.Sprintf("%s/%s", user.Owner, user.Name) } -func HasMail(email string) string { - user := GetMail(email) +func HasMail(application *Application, email string) string { + user := GetMail(application.Organization, email) if user != nil { return user.getId() } return "" } -func HasGithub(github string) string { - user := GetGithub(github) +func HasGithub(application *Application, github string) string { + user := GetGithub(application.Organization, github) if user != nil { return user.getId() } diff --git a/object/user.go b/object/user.go index 5d7f4bce..ec78eed5 100644 --- a/object/user.go +++ b/object/user.go @@ -32,6 +32,7 @@ type User struct { Email string `xorm:"varchar(100)" json:"email"` Phone string `xorm:"varchar(100)" json:"phone"` Affiliation string `xorm:"varchar(100)" json:"affiliation"` + Tag string `xorm:"varchar(100)" json:"tag"` IsAdmin bool `json:"isAdmin"` Github string `xorm:"varchar(100)" json:"github"` @@ -119,8 +120,8 @@ func DeleteUser(user *User) bool { return affected != 0 } -func GetMail(email string) *User { - user := User{Email: email} +func GetMail(organizationName string, email string) *User { + user := User{Owner: organizationName, Email: email} existed, err := adapter.engine.Get(&user) if err != nil { panic(err) @@ -133,8 +134,8 @@ func GetMail(email string) *User { } } -func GetGithub(github string) *User { - user := User{Github: github} +func GetGithub(organizationName string, github string) *User { + user := User{Owner: organizationName, Github: github} existed, err := adapter.engine.Get(&user) if err != nil { panic(err) diff --git a/web/src/App.js b/web/src/App.js index fa540c1e..33c922c7 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -273,7 +273,7 @@ class App extends Component { this.renderHomeIfLoggedIn()}/> - + this.renderLoginIfNotLoggedIn()}/> this.renderLoginIfNotLoggedIn()}/> this.renderLoginIfNotLoggedIn()}/> diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 56966e10..918d7798 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -198,6 +198,24 @@ class UserEditPage extends React.Component { }} /> + + + Tag: + + + { + this.updateUserField('tag', e.target.value); + }} /> + + + + + GitHub: + + + + + Is Admin: diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index 9cff309f..faa5bbf8 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -104,7 +104,7 @@ class UserListPage extends React.Component { title: 'Name', dataIndex: 'name', key: 'name', - width: '120px', + width: '100px', sorter: (a, b) => a.name.localeCompare(b.name), render: (text, record, index) => { return ( @@ -124,13 +124,13 @@ class UserListPage extends React.Component { return Setting.getFormattedDate(text); } }, - { - title: 'Password Type', - dataIndex: 'passwordType', - key: 'passwordType', - width: '150px', - sorter: (a, b) => a.passwordType.localeCompare(b.passwordType), - }, + // { + // title: 'Password Type', + // dataIndex: 'passwordType', + // key: 'passwordType', + // width: '150px', + // sorter: (a, b) => a.passwordType.localeCompare(b.passwordType), + // }, // { // title: 'Password', // dataIndex: 'password', @@ -162,7 +162,7 @@ class UserListPage extends React.Component { title: 'Email', dataIndex: 'email', key: 'email', - width: '180px', + width: '160px', sorter: (a, b) => a.email.localeCompare(b.email), render: (text, record, index) => { return ( @@ -172,13 +172,13 @@ class UserListPage extends React.Component { ) } }, - { - title: 'Phone', - dataIndex: 'phone', - key: 'phone', - width: '120px', - sorter: (a, b) => a.phone.localeCompare(b.phone), - }, + // { + // title: 'Phone', + // dataIndex: 'phone', + // key: 'phone', + // width: '120px', + // sorter: (a, b) => a.phone.localeCompare(b.phone), + // }, { title: 'Affiliation', dataIndex: 'affiliation', @@ -186,6 +186,13 @@ class UserListPage extends React.Component { width: '120px', sorter: (a, b) => a.affiliation.localeCompare(b.affiliation), }, + { + title: 'Tag', + dataIndex: 'tag', + key: 'tag', + width: '100px', + sorter: (a, b) => a.tag.localeCompare(b.tag), + }, { title: 'Is Admin', dataIndex: 'isAdmin', diff --git a/web/src/auth/AuthBackend.js b/web/src/auth/AuthBackend.js index 0068a8fb..c58df1d0 100644 --- a/web/src/auth/AuthBackend.js +++ b/web/src/auth/AuthBackend.js @@ -44,8 +44,8 @@ export function logout() { }).then(res => res.json()); } -export function authLogin(providerName, code, state, redirectUrl, method) { - return fetch(`${authConfig.serverUrl}/api/auth/login?provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUrl}&method=${method}`, { +export function authLogin(applicationName, providerName, code, state, redirectUrl, method) { + return fetch(`${authConfig.serverUrl}/api/auth/login?application=${applicationName}&provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUrl}&method=${method}`, { method: 'GET', credentials: 'include', }).then(res => res.json()); diff --git a/web/src/auth/AuthCallback.js b/web/src/auth/AuthCallback.js index b1aaaf02..496351d6 100644 --- a/web/src/auth/AuthCallback.js +++ b/web/src/auth/AuthCallback.js @@ -23,7 +23,7 @@ class AuthCallback extends React.Component { const params = new URLSearchParams(this.props.location.search); this.state = { classes: props, - providerType: props.match.params.providerType, + applicationName: props.match.params.applicationName, providerName: props.match.params.providerName, method: props.match.params.method, state: params.get("state"), @@ -48,8 +48,8 @@ class AuthCallback extends React.Component { authLogin() { let redirectUrl; - redirectUrl = `${window.location.origin}/callback/${this.state.providerType}/${this.state.providerName}/${this.state.method}`; - AuthBackend.authLogin(this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.method) + redirectUrl = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`; + AuthBackend.authLogin(this.state.applicationName, this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.method) .then((res) => { if (res.status === "ok") { window.location.href = '/'; diff --git a/web/src/auth/Face.js b/web/src/auth/Face.js index 3af577be..28c89f85 100644 --- a/web/src/auth/Face.js +++ b/web/src/auth/Face.js @@ -128,7 +128,7 @@ class Face extends React.Component { { this.getApplicationObj().providerObjs.map(provider => { return ( - + {provider.displayName} ); diff --git a/web/src/auth/Provider.js b/web/src/auth/Provider.js index c6ea7036..d64d5c44 100644 --- a/web/src/auth/Provider.js +++ b/web/src/auth/Provider.js @@ -42,8 +42,8 @@ export function getAuthLogo(provider) { } } -export function getAuthUrl(provider, method) { - const redirectUri = `${window.location.origin}/callback/${provider.type}/${provider.name}/${method}`; +export function getAuthUrl(application, provider, method) { + const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}`; if (provider.type === "google") { return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${AuthState}`; } else if (provider.type === "github") {