mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
Check user under org.
This commit is contained in:
@ -42,12 +42,14 @@ var githubOauthConfig = &oauth2.Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) AuthLogin() {
|
func (c *ApiController) AuthLogin() {
|
||||||
|
applicationName := c.Input().Get("application")
|
||||||
providerName := c.Input().Get("provider")
|
providerName := c.Input().Get("provider")
|
||||||
code := c.Input().Get("code")
|
code := c.Input().Get("code")
|
||||||
state := c.Input().Get("state")
|
state := c.Input().Get("state")
|
||||||
method := c.Input().Get("method")
|
method := c.Input().Get("method")
|
||||||
RedirectURL := c.Input().Get("redirect_url")
|
RedirectURL := c.Input().Get("redirect_url")
|
||||||
|
|
||||||
|
application := object.GetApplication(fmt.Sprintf("admin/%s", applicationName))
|
||||||
provider := object.GetProvider(fmt.Sprintf("admin/%s", providerName))
|
provider := object.GetProvider(fmt.Sprintf("admin/%s", providerName))
|
||||||
githubOauthConfig.ClientID = provider.ClientId
|
githubOauthConfig.ClientID = provider.ClientId
|
||||||
githubOauthConfig.ClientSecret = provider.ClientSecret
|
githubOauthConfig.ClientSecret = provider.ClientSecret
|
||||||
@ -132,7 +134,7 @@ func (c *ApiController) AuthLogin() {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if method == "signup" {
|
if method == "signup" {
|
||||||
userId := object.HasGithub(tempUserAccount.Login)
|
userId := object.HasGithub(application, tempUserAccount.Login)
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
//if len(object.GetMemberAvatar(userId)) == 0 {
|
//if len(object.GetMemberAvatar(userId)) == 0 {
|
||||||
// avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId)
|
// avatar := UploadAvatarToOSS(tempUserAccount.AvatarUrl, userId)
|
||||||
@ -142,7 +144,7 @@ func (c *ApiController) AuthLogin() {
|
|||||||
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
||||||
res.IsSignedUp = true
|
res.IsSignedUp = true
|
||||||
} else {
|
} else {
|
||||||
if userId := object.HasMail(res.Email); userId != "" {
|
if userId := object.HasMail(application, res.Email); userId != "" {
|
||||||
c.SetSessionUser(userId)
|
c.SetSessionUser(userId)
|
||||||
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
util.LogInfo(c.Ctx, "API: [%s] signed in", userId)
|
||||||
res.IsSignedUp = true
|
res.IsSignedUp = true
|
||||||
|
4
main.go
4
main.go
@ -15,8 +15,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/astaxie/beego/plugins/cors"
|
"github.com/astaxie/beego/plugins/cors"
|
||||||
"github.com/casdoor/casdoor/controllers"
|
"github.com/casdoor/casdoor/controllers"
|
||||||
@ -47,7 +45,7 @@ func main() {
|
|||||||
beego.BConfig.WebConfig.Session.SessionProvider="file"
|
beego.BConfig.WebConfig.Session.SessionProvider="file"
|
||||||
beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp"
|
beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp"
|
||||||
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365
|
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365
|
||||||
beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode
|
//beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode
|
||||||
|
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,16 @@ func (user *User) getId() string {
|
|||||||
return fmt.Sprintf("%s/%s", user.Owner, user.Name)
|
return fmt.Sprintf("%s/%s", user.Owner, user.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasMail(email string) string {
|
func HasMail(application *Application, email string) string {
|
||||||
user := GetMail(email)
|
user := GetMail(application.Organization, email)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
return user.getId()
|
return user.getId()
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasGithub(github string) string {
|
func HasGithub(application *Application, github string) string {
|
||||||
user := GetGithub(github)
|
user := GetGithub(application.Organization, github)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
return user.getId()
|
return user.getId()
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ type User struct {
|
|||||||
Email string `xorm:"varchar(100)" json:"email"`
|
Email string `xorm:"varchar(100)" json:"email"`
|
||||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||||
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
||||||
|
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||||
IsAdmin bool `json:"isAdmin"`
|
IsAdmin bool `json:"isAdmin"`
|
||||||
|
|
||||||
Github string `xorm:"varchar(100)" json:"github"`
|
Github string `xorm:"varchar(100)" json:"github"`
|
||||||
@ -119,8 +120,8 @@ func DeleteUser(user *User) bool {
|
|||||||
return affected != 0
|
return affected != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMail(email string) *User {
|
func GetMail(organizationName string, email string) *User {
|
||||||
user := User{Email: email}
|
user := User{Owner: organizationName, Email: email}
|
||||||
existed, err := adapter.engine.Get(&user)
|
existed, err := adapter.engine.Get(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -133,8 +134,8 @@ func GetMail(email string) *User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGithub(github string) *User {
|
func GetGithub(organizationName string, github string) *User {
|
||||||
user := User{Github: github}
|
user := User{Owner: organizationName, Github: github}
|
||||||
existed, err := adapter.engine.Get(&user)
|
existed, err := adapter.engine.Get(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -273,7 +273,7 @@ class App extends Component {
|
|||||||
</Header>
|
</Header>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<LoginPage onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
|
<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="/" 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="/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} />)}/>
|
<Route exact path="/organizations" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationListPage account={this.state.account} {...props} />)}/>
|
||||||
|
@ -198,6 +198,24 @@ class UserEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</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'}} >
|
<Row style={{marginTop: '20px'}} >
|
||||||
<Col style={{marginTop: '5px'}} span={2}>
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
Is Admin:
|
Is Admin:
|
||||||
|
@ -104,7 +104,7 @@ class UserListPage extends React.Component {
|
|||||||
title: 'Name',
|
title: 'Name',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
width: '120px',
|
width: '100px',
|
||||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
@ -124,13 +124,13 @@ class UserListPage extends React.Component {
|
|||||||
return Setting.getFormattedDate(text);
|
return Setting.getFormattedDate(text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
title: 'Password Type',
|
// title: 'Password Type',
|
||||||
dataIndex: 'passwordType',
|
// dataIndex: 'passwordType',
|
||||||
key: 'passwordType',
|
// key: 'passwordType',
|
||||||
width: '150px',
|
// width: '150px',
|
||||||
sorter: (a, b) => a.passwordType.localeCompare(b.passwordType),
|
// sorter: (a, b) => a.passwordType.localeCompare(b.passwordType),
|
||||||
},
|
// },
|
||||||
// {
|
// {
|
||||||
// title: 'Password',
|
// title: 'Password',
|
||||||
// dataIndex: 'password',
|
// dataIndex: 'password',
|
||||||
@ -162,7 +162,7 @@ class UserListPage extends React.Component {
|
|||||||
title: 'Email',
|
title: 'Email',
|
||||||
dataIndex: 'email',
|
dataIndex: 'email',
|
||||||
key: 'email',
|
key: 'email',
|
||||||
width: '180px',
|
width: '160px',
|
||||||
sorter: (a, b) => a.email.localeCompare(b.email),
|
sorter: (a, b) => a.email.localeCompare(b.email),
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
@ -172,13 +172,13 @@ class UserListPage extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
title: 'Phone',
|
// title: 'Phone',
|
||||||
dataIndex: 'phone',
|
// dataIndex: 'phone',
|
||||||
key: 'phone',
|
// key: 'phone',
|
||||||
width: '120px',
|
// width: '120px',
|
||||||
sorter: (a, b) => a.phone.localeCompare(b.phone),
|
// sorter: (a, b) => a.phone.localeCompare(b.phone),
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
title: 'Affiliation',
|
title: 'Affiliation',
|
||||||
dataIndex: 'affiliation',
|
dataIndex: 'affiliation',
|
||||||
@ -186,6 +186,13 @@ class UserListPage extends React.Component {
|
|||||||
width: '120px',
|
width: '120px',
|
||||||
sorter: (a, b) => a.affiliation.localeCompare(b.affiliation),
|
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',
|
title: 'Is Admin',
|
||||||
dataIndex: 'isAdmin',
|
dataIndex: 'isAdmin',
|
||||||
|
@ -44,8 +44,8 @@ export function logout() {
|
|||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function authLogin(providerName, code, state, redirectUrl, method) {
|
export function authLogin(applicationName, providerName, code, state, redirectUrl, method) {
|
||||||
return fetch(`${authConfig.serverUrl}/api/auth/login?provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUrl}&method=${method}`, {
|
return fetch(`${authConfig.serverUrl}/api/auth/login?application=${applicationName}&provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUrl}&method=${method}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
|
@ -23,7 +23,7 @@ class AuthCallback extends React.Component {
|
|||||||
const params = new URLSearchParams(this.props.location.search);
|
const params = new URLSearchParams(this.props.location.search);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
providerType: props.match.params.providerType,
|
applicationName: props.match.params.applicationName,
|
||||||
providerName: props.match.params.providerName,
|
providerName: props.match.params.providerName,
|
||||||
method: props.match.params.method,
|
method: props.match.params.method,
|
||||||
state: params.get("state"),
|
state: params.get("state"),
|
||||||
@ -48,8 +48,8 @@ class AuthCallback extends React.Component {
|
|||||||
|
|
||||||
authLogin() {
|
authLogin() {
|
||||||
let redirectUrl;
|
let redirectUrl;
|
||||||
redirectUrl = `${window.location.origin}/callback/${this.state.providerType}/${this.state.providerName}/${this.state.method}`;
|
redirectUrl = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`;
|
||||||
AuthBackend.authLogin(this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.method)
|
AuthBackend.authLogin(this.state.applicationName, this.state.providerName, this.state.code, this.state.state, redirectUrl, this.state.method)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
|
@ -128,7 +128,7 @@ class Face extends React.Component {
|
|||||||
{
|
{
|
||||||
this.getApplicationObj().providerObjs.map(provider => {
|
this.getApplicationObj().providerObjs.map(provider => {
|
||||||
return (
|
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"}} />
|
<img width={30} height={30} src={Provider.getAuthLogo(provider)} alt={provider.displayName} style={{margin: "3px"}} />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
@ -42,8 +42,8 @@ export function getAuthLogo(provider) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAuthUrl(provider, method) {
|
export function getAuthUrl(application, provider, method) {
|
||||||
const redirectUri = `${window.location.origin}/callback/${provider.type}/${provider.name}/${method}`;
|
const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}`;
|
||||||
if (provider.type === "google") {
|
if (provider.type === "google") {
|
||||||
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${AuthState}`;
|
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${AuthState}`;
|
||||||
} else if (provider.type === "github") {
|
} else if (provider.type === "github") {
|
||||||
|
Reference in New Issue
Block a user