mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
Finish the prompt page logic.
This commit is contained in:
@ -153,7 +153,10 @@ func (c *ApiController) Signup() {
|
|||||||
}
|
}
|
||||||
object.AddUser(user)
|
object.AddUser(user)
|
||||||
|
|
||||||
//c.SetSessionUser(user)
|
if application.HasPromptPage() {
|
||||||
|
// The prompt page needs the user to be signed in
|
||||||
|
c.SetSessionUser(user.GetId())
|
||||||
|
}
|
||||||
|
|
||||||
object.DisableVerificationCode(form.Email)
|
object.DisableVerificationCode(form.Email)
|
||||||
object.DisableVerificationCode(checkPhone)
|
object.DisableVerificationCode(checkPhone)
|
||||||
|
@ -309,7 +309,7 @@ func (c *ApiController) Login() {
|
|||||||
oldUser = object.GetUserByField(application.Organization, provider.Type, userInfo.Username)
|
oldUser = object.GetUserByField(application.Organization, provider.Type, userInfo.Username)
|
||||||
}
|
}
|
||||||
if oldUser != nil {
|
if oldUser != nil {
|
||||||
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s (%s) is already linked to another account", provider.Type, userInfo.Username, userInfo.DisplayName)}
|
resp = &Response{Status: "error", Msg: fmt.Sprintf("The account for provider: %s and username: %s (%s) is already linked to another account: %s (%s)", provider.Type, userInfo.Username, userInfo.DisplayName, oldUser.Name, oldUser.DisplayName)}
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
|
@ -180,62 +180,3 @@ func DeleteApplication(application *Application) bool {
|
|||||||
|
|
||||||
return affected != 0
|
return affected != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (application *Application) getProviderByCategory(category string) *Provider {
|
|
||||||
providers := GetProviders(application.Owner)
|
|
||||||
m := map[string]*Provider{}
|
|
||||||
for _, provider := range providers {
|
|
||||||
if provider.Category != category {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
m[provider.Name] = provider
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, providerItem := range application.Providers {
|
|
||||||
if provider, ok := m[providerItem.Name]; ok {
|
|
||||||
return provider
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) GetEmailProvider() *Provider {
|
|
||||||
return application.getProviderByCategory("Email")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) GetSmsProvider() *Provider {
|
|
||||||
return application.getProviderByCategory("SMS")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) getSignupItem(itemName string) *SignupItem {
|
|
||||||
for _, signupItem := range application.SignupItems {
|
|
||||||
if signupItem.Name == itemName {
|
|
||||||
return signupItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) IsSignupItemEnabled(itemName string) bool {
|
|
||||||
return application.getSignupItem(itemName) != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) IsSignupItemVisible(itemName string) bool {
|
|
||||||
signupItem := application.getSignupItem(itemName)
|
|
||||||
if signupItem == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return signupItem.Visible
|
|
||||||
}
|
|
||||||
|
|
||||||
func (application *Application) GetSignupItemRule(itemName string) string {
|
|
||||||
signupItem := application.getSignupItem(itemName)
|
|
||||||
if signupItem == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return signupItem.Rule
|
|
||||||
}
|
|
||||||
|
102
object/application_item.go
Normal file
102
object/application_item.go
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package object
|
||||||
|
|
||||||
|
func (application *Application) getProviderByCategory(category string) *Provider {
|
||||||
|
providers := GetProviders(application.Owner)
|
||||||
|
m := map[string]*Provider{}
|
||||||
|
for _, provider := range providers {
|
||||||
|
if provider.Category != category {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m[provider.Name] = provider
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, providerItem := range application.Providers {
|
||||||
|
if provider, ok := m[providerItem.Name]; ok {
|
||||||
|
return provider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) GetEmailProvider() *Provider {
|
||||||
|
return application.getProviderByCategory("Email")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) GetSmsProvider() *Provider {
|
||||||
|
return application.getProviderByCategory("SMS")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) getSignupItem(itemName string) *SignupItem {
|
||||||
|
for _, signupItem := range application.SignupItems {
|
||||||
|
if signupItem.Name == itemName {
|
||||||
|
return signupItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) IsSignupItemEnabled(itemName string) bool {
|
||||||
|
return application.getSignupItem(itemName) != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) IsSignupItemVisible(itemName string) bool {
|
||||||
|
signupItem := application.getSignupItem(itemName)
|
||||||
|
if signupItem == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return signupItem.Visible
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) GetSignupItemRule(itemName string) string {
|
||||||
|
signupItem := application.getSignupItem(itemName)
|
||||||
|
if signupItem == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return signupItem.Rule
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) getAllPromptedProviderItems() []*ProviderItem {
|
||||||
|
res := []*ProviderItem{}
|
||||||
|
for _, providerItem := range application.Providers {
|
||||||
|
if providerItem.isProviderPrompted() {
|
||||||
|
res = append(res, providerItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) isAffiliationPrompted() bool {
|
||||||
|
signupItem := application.getSignupItem("Affiliation")
|
||||||
|
if signupItem == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return signupItem.Prompted
|
||||||
|
}
|
||||||
|
|
||||||
|
func (application *Application) HasPromptPage() bool {
|
||||||
|
providerItems := application.getAllPromptedProviderItems()
|
||||||
|
if len(providerItems) != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return application.isAffiliationPrompted()
|
||||||
|
}
|
@ -32,3 +32,11 @@ func (application *Application) GetProviderItem(providerName string) *ProviderIt
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pi *ProviderItem) isProviderVisible() bool {
|
||||||
|
return pi.Provider.Category == "OAuth"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pi *ProviderItem) isProviderPrompted() bool {
|
||||||
|
return pi.isProviderVisible() && pi.Prompted
|
||||||
|
}
|
||||||
|
@ -78,6 +78,36 @@ export function isProviderPrompted(providerItem) {
|
|||||||
return isProviderVisible(providerItem) && providerItem.prompted;
|
return isProviderVisible(providerItem) && providerItem.prompted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAllPromptedProviderItems(application) {
|
||||||
|
return application.providers.filter(providerItem => isProviderPrompted(providerItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSignupItem(application, itemName) {
|
||||||
|
const signupItems = application.signupItems.filter(signupItem => signupItem.name === itemName);
|
||||||
|
if (signupItems.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return signupItems[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAffiliationPrompted(application) {
|
||||||
|
const signupItem = getSignupItem(application, "Affiliation");
|
||||||
|
if (signupItem === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return signupItem.prompted;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasPromptPage(application) {
|
||||||
|
const providerItems = getAllPromptedProviderItems(application);
|
||||||
|
if (providerItems.length !== 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAffiliationPrompted(application);
|
||||||
|
}
|
||||||
|
|
||||||
export function parseJson(s) {
|
export function parseJson(s) {
|
||||||
if (s === "") {
|
if (s === "") {
|
||||||
return null;
|
return null;
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import {Button, Col, Row} from "antd";
|
import {Link} from "react-router-dom";
|
||||||
|
import {Button, Col, Result, Row} from "antd";
|
||||||
import * as ApplicationBackend from "../backend/ApplicationBackend";
|
import * as ApplicationBackend from "../backend/ApplicationBackend";
|
||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
@ -89,21 +90,8 @@ class PromptPage extends React.Component {
|
|||||||
this.submitUserEdit(false);
|
this.submitUserEdit(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllPromptedProviderItems(application) {
|
|
||||||
return application.providers.filter(providerItem => Setting.isProviderPrompted(providerItem));
|
|
||||||
}
|
|
||||||
|
|
||||||
isAffiliationPrompted(application) {
|
|
||||||
const signupItems = application.signupItems.filter(signupItem => signupItem.name === "Affiliation");
|
|
||||||
if (signupItems.length === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return signupItems[0].prompted;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderAffiliation(application) {
|
renderAffiliation(application) {
|
||||||
if (!this.isAffiliationPrompted(application)) {
|
if (!Setting.isAffiliationPrompted(application)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +136,7 @@ class PromptPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isAffiliationAnswered(application) {
|
isAffiliationAnswered(application) {
|
||||||
if (!this.isAffiliationPrompted(application)) {
|
if (!Setting.isAffiliationPrompted(application)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +151,7 @@ class PromptPage extends React.Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const providerItems = this.getAllPromptedProviderItems(application);
|
const providerItems = Setting.getAllPromptedProviderItems(application);
|
||||||
for (let i = 0; i < providerItems.length; i ++) {
|
for (let i = 0; i < providerItems.length; i ++) {
|
||||||
if (!this.isProviderItemAnswered(application, providerItems[i])) {
|
if (!this.isProviderItemAnswered(application, providerItems[i])) {
|
||||||
return false;
|
return false;
|
||||||
@ -201,6 +189,26 @@ class PromptPage extends React.Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Setting.hasPromptPage(application)) {
|
||||||
|
return (
|
||||||
|
<Result
|
||||||
|
status="error"
|
||||||
|
title="Sign Up Error"
|
||||||
|
subTitle={"You are unexpected to see this prompt page"}
|
||||||
|
extra={[
|
||||||
|
<Link onClick={() => {
|
||||||
|
Setting.goToLogin(this, application);
|
||||||
|
}}>
|
||||||
|
<Button type="primary" key="signin">
|
||||||
|
Sign In
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
</Result>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={24} style={{display: "flex", justifyContent: "center"}}>
|
<Col span={24} style={{display: "flex", justifyContent: "center"}}>
|
||||||
|
@ -97,7 +97,11 @@ class SignupPage extends React.Component {
|
|||||||
if (authConfig.appName === application.name) {
|
if (authConfig.appName === application.name) {
|
||||||
return "/result";
|
return "/result";
|
||||||
} else {
|
} else {
|
||||||
return `/result/${application.name}`;
|
if (Setting.hasPromptPage(application)) {
|
||||||
|
return `/prompt/${application.name}`;
|
||||||
|
} else {
|
||||||
|
return `/result/${application.name}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user