mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
Check user under org.
This commit is contained in:
@ -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
|
||||
|
4
main.go
4
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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -273,7 +273,7 @@ class App extends Component {
|
||||
</Header>
|
||||
<Switch>
|
||||
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<LoginPage onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
|
||||
<Route exact path="/callback/:providerType/:providerName/:method" component={AuthCallback}/>
|
||||
<Route exact path="/callback/:applicationName/:providerName/:method" component={AuthCallback}/>
|
||||
<Route exact path="/" render={(props) => this.renderLoginIfNotLoggedIn(<HomePage account={this.state.account} onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
|
||||
<Route exact path="/account" render={(props) => this.renderLoginIfNotLoggedIn(<AccountPage account={this.state.account} {...props} />)}/>
|
||||
<Route exact path="/organizations" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationListPage account={this.state.account} {...props} />)}/>
|
||||
|
@ -198,6 +198,24 @@ class UserEditPage extends React.Component {
|
||||
}} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{marginTop: '20px'}} >
|
||||
<Col style={{marginTop: '5px'}} span={2}>
|
||||
Tag:
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<Input value={this.state.user.tag} onChange={e => {
|
||||
this.updateUserField('tag', e.target.value);
|
||||
}} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{marginTop: '20px'}} >
|
||||
<Col style={{marginTop: '5px'}} span={2}>
|
||||
GitHub:
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<Input value={this.state.user.github} disabled={true} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{marginTop: '20px'}} >
|
||||
<Col style={{marginTop: '5px'}} span={2}>
|
||||
Is Admin:
|
||||
|
@ -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',
|
||||
|
@ -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());
|
||||
|
@ -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 = '/';
|
||||
|
@ -128,7 +128,7 @@ class Face extends React.Component {
|
||||
{
|
||||
this.getApplicationObj().providerObjs.map(provider => {
|
||||
return (
|
||||
<a href={Provider.getAuthUrl(provider, "signup")}>
|
||||
<a href={Provider.getAuthUrl(this.getApplicationObj(), provider, "signup")}>
|
||||
<img width={30} height={30} src={Provider.getAuthLogo(provider)} alt={provider.displayName} style={{margin: "3px"}} />
|
||||
</a>
|
||||
);
|
||||
|
@ -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") {
|
||||
|
Reference in New Issue
Block a user