mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-15 05:03:49 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef14c84edc | |||
cb5c7667b5 | |||
920ed87f75 | |||
6598f0ccdf | |||
8e71e23d75 | |||
146a369f80 |
@ -66,7 +66,11 @@ func GetConfigBool(key string) bool {
|
||||
func GetConfigInt64(key string) (int64, error) {
|
||||
value := GetConfigString(key)
|
||||
num, err := strconv.ParseInt(value, 10, 64)
|
||||
return num, err
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("GetConfigInt64(%s) error, %s", key, err.Error())
|
||||
}
|
||||
|
||||
return num, nil
|
||||
}
|
||||
|
||||
func GetConfigDataSourceName() string {
|
||||
|
@ -16,6 +16,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/utils/pagination"
|
||||
@ -460,7 +461,18 @@ func (c *ApiController) IntrospectToken() {
|
||||
}
|
||||
|
||||
if token != nil {
|
||||
application, err = object.GetApplication(fmt.Sprintf("%s/%s", token.Owner, token.Application))
|
||||
if err != nil {
|
||||
c.ResponseTokenError(err.Error())
|
||||
return
|
||||
}
|
||||
if application == nil {
|
||||
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist"), token.Application))
|
||||
return
|
||||
}
|
||||
|
||||
introspectionResponse.TokenType = token.TokenType
|
||||
introspectionResponse.ClientId = application.ClientId
|
||||
}
|
||||
|
||||
c.Data["json"] = introspectionResponse
|
||||
|
@ -220,10 +220,15 @@ func checkSigninErrorTimes(user *User, lang string) error {
|
||||
}
|
||||
|
||||
func CheckPassword(user *User, password string, lang string, options ...bool) error {
|
||||
if password == "" {
|
||||
return fmt.Errorf(i18n.Translate(lang, "check:Password cannot be empty"))
|
||||
}
|
||||
|
||||
enableCaptcha := false
|
||||
if len(options) > 0 {
|
||||
enableCaptcha = options[0]
|
||||
}
|
||||
|
||||
// check the login error times
|
||||
if !enableCaptcha {
|
||||
err := checkSigninErrorTimes(user, lang)
|
||||
@ -236,35 +241,31 @@ func CheckPassword(user *User, password string, lang string, options ...bool) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if organization == nil {
|
||||
return fmt.Errorf(i18n.Translate(lang, "check:Organization does not exist"))
|
||||
}
|
||||
|
||||
if password == "" {
|
||||
return fmt.Errorf(i18n.Translate(lang, "check:Password cannot be empty"))
|
||||
}
|
||||
|
||||
passwordType := user.PasswordType
|
||||
if passwordType == "" {
|
||||
passwordType = organization.PasswordType
|
||||
}
|
||||
|
||||
credManager := cred.GetCredManager(passwordType)
|
||||
if credManager != nil {
|
||||
if organization.MasterPassword != "" {
|
||||
if password == organization.MasterPassword || credManager.IsPasswordCorrect(password, organization.MasterPassword, organization.PasswordSalt) {
|
||||
return resetUserSigninErrorTimes(user)
|
||||
}
|
||||
}
|
||||
|
||||
if credManager.IsPasswordCorrect(password, user.Password, organization.PasswordSalt) || credManager.IsPasswordCorrect(password, user.Password, user.PasswordSalt) {
|
||||
return resetUserSigninErrorTimes(user)
|
||||
}
|
||||
|
||||
return recordSigninErrorInfo(user, lang, enableCaptcha)
|
||||
} else {
|
||||
if credManager == nil {
|
||||
return fmt.Errorf(i18n.Translate(lang, "check:unsupported password type: %s"), organization.PasswordType)
|
||||
}
|
||||
|
||||
if organization.MasterPassword != "" {
|
||||
if password == organization.MasterPassword || credManager.IsPasswordCorrect(password, organization.MasterPassword, organization.PasswordSalt) {
|
||||
return resetUserSigninErrorTimes(user)
|
||||
}
|
||||
}
|
||||
|
||||
if !credManager.IsPasswordCorrect(password, user.Password, organization.PasswordSalt) && !credManager.IsPasswordCorrect(password, user.Password, user.PasswordSalt) {
|
||||
return recordSigninErrorInfo(user, lang, enableCaptcha)
|
||||
}
|
||||
|
||||
return resetUserSigninErrorTimes(user)
|
||||
}
|
||||
|
||||
func CheckPasswordComplexityByOrg(organization *Organization, password string) string {
|
||||
|
@ -103,7 +103,7 @@ func GetDashboard(owner string) (*map[string][]int64, error) {
|
||||
func countCreatedBefore(dashboardMapItem DashboardMapItem, before time.Time) int64 {
|
||||
count := dashboardMapItem.itemCount
|
||||
for _, e := range dashboardMapItem.dashboardDateItems {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", e.CreatedTime)
|
||||
createdTime, _ := time.Parse(time.RFC3339, e.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
|
@ -49,17 +49,21 @@ func (plan *Plan) GetId() string {
|
||||
return fmt.Sprintf("%s/%s", plan.Owner, plan.Name)
|
||||
}
|
||||
|
||||
func GetDuration(period string) (startTime time.Time, endTime time.Time) {
|
||||
func getDuration(period string) (string, string, error) {
|
||||
startTime := time.Now()
|
||||
var endTime time.Time
|
||||
|
||||
if period == PeriodYearly {
|
||||
startTime = time.Now()
|
||||
endTime = startTime.AddDate(1, 0, 0)
|
||||
} else if period == PeriodMonthly {
|
||||
startTime = time.Now()
|
||||
endTime = startTime.AddDate(0, 1, 0)
|
||||
} else {
|
||||
panic(fmt.Sprintf("invalid period: %s", period))
|
||||
return "", "", fmt.Errorf("invalid period: %s", period)
|
||||
}
|
||||
return
|
||||
|
||||
startTimeString := startTime.Format(time.RFC3339)
|
||||
endTimeString := endTime.Format(time.RFC3339)
|
||||
return startTimeString, endTimeString, nil
|
||||
}
|
||||
|
||||
func GetPlanCount(owner, field, value string) (int64, error) {
|
||||
|
@ -206,11 +206,17 @@ func BuyProduct(id string, user *User, providerName, pricingName, planName, host
|
||||
if plan == nil {
|
||||
return nil, nil, fmt.Errorf("the plan: %s does not exist", planName)
|
||||
}
|
||||
sub := NewSubscription(owner, user.Name, plan.Name, paymentName, plan.Period)
|
||||
|
||||
sub, err := NewSubscription(owner, user.Name, plan.Name, paymentName, plan.Period)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
_, err = AddSubscription(sub)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
returnUrl = fmt.Sprintf("%s/buy-plan/%s/%s/result?subscription=%s", originFrontend, owner, pricingName, sub.Name)
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ type Subscription struct {
|
||||
Plan string `xorm:"varchar(100)" json:"plan"`
|
||||
Payment string `xorm:"varchar(100)" json:"payment"`
|
||||
|
||||
StartTime time.Time `json:"startTime"`
|
||||
EndTime time.Time `json:"endTime"`
|
||||
StartTime string `xorm:"varchar(100)" json:"startTime"`
|
||||
EndTime string `xorm:"varchar(100)" json:"endTime"`
|
||||
Period string `xorm:"varchar(100)" json:"period"`
|
||||
State SubscriptionState `xorm:"varchar(100)" json:"state"`
|
||||
}
|
||||
@ -84,9 +84,19 @@ func (sub *Subscription) UpdateState() error {
|
||||
}
|
||||
|
||||
if sub.State == SubStateActive || sub.State == SubStateUpcoming || sub.State == SubStateExpired {
|
||||
if sub.EndTime.Before(time.Now()) {
|
||||
startTime, err := time.Parse(time.RFC3339, sub.StartTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
endTime, err := time.Parse(time.RFC3339, sub.EndTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if endTime.Before(time.Now()) {
|
||||
sub.State = SubStateExpired
|
||||
} else if sub.StartTime.After(time.Now()) {
|
||||
} else if startTime.After(time.Now()) {
|
||||
sub.State = SubStateUpcoming
|
||||
} else {
|
||||
sub.State = SubStateActive
|
||||
@ -103,10 +113,15 @@ func (sub *Subscription) UpdateState() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSubscription(owner, userName, planName, paymentName, period string) *Subscription {
|
||||
startTime, endTime := GetDuration(period)
|
||||
func NewSubscription(owner, userName, planName, paymentName, period string) (*Subscription, error) {
|
||||
startTime, endTime, err := getDuration(period)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id := util.GenerateId()[:6]
|
||||
return &Subscription{
|
||||
|
||||
res := &Subscription{
|
||||
Owner: owner,
|
||||
Name: "sub_" + id,
|
||||
DisplayName: "New Subscription - " + id,
|
||||
@ -121,6 +136,7 @@ func NewSubscription(owner, userName, planName, paymentName, period string) *Sub
|
||||
Period: period,
|
||||
State: SubStatePending, // waiting for payment complete
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func GetSubscriptionCount(owner, field, value string) (int64, error) {
|
||||
|
@ -66,6 +66,10 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
responseError(ctx, err.Error())
|
||||
return
|
||||
}
|
||||
if application == nil {
|
||||
responseError(ctx, fmt.Sprintf("No application is found for userId: app/%s", token.Application))
|
||||
return
|
||||
}
|
||||
|
||||
setSessionUser(ctx, userId)
|
||||
setSessionOidc(ctx, token.Scope, application.ClientId)
|
||||
|
@ -385,7 +385,7 @@ class ForgetPage extends React.Component {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Popover placement="right" content={this.state.passwordPopover} open={this.state.passwordPopoverOpen}>
|
||||
<Popover placement={window.innerWidth >= 960 ? "right" : "top"} content={this.state.passwordPopover} open={this.state.passwordPopoverOpen}>
|
||||
<Form.Item
|
||||
name="newPassword"
|
||||
hidden={this.state.current !== 2}
|
||||
@ -415,7 +415,7 @@ class ForgetPage extends React.Component {
|
||||
}}
|
||||
onFocus={() => {
|
||||
this.setState({
|
||||
passwordPopoverOpen: true,
|
||||
passwordPopoverOpen: application.organizationObj.passwordOptions?.length > 0,
|
||||
passwordPopover: PasswordChecker.renderPasswordPopover(application.organizationObj.passwordOptions, this.form.current?.getFieldValue("newPassword") ?? ""),
|
||||
});
|
||||
}}
|
||||
|
@ -607,7 +607,7 @@ class SignupPage extends React.Component {
|
||||
}
|
||||
} else if (signupItem.name === "Password") {
|
||||
return (
|
||||
<Popover placement="right" content={this.state.passwordPopover} open={this.state.passwordPopoverOpen}>
|
||||
<Popover placement={window.innerWidth >= 960 ? "right" : "top"} content={this.state.passwordPopover} open={this.state.passwordPopoverOpen}>
|
||||
<Form.Item
|
||||
name="password"
|
||||
className="signup-password"
|
||||
@ -635,7 +635,7 @@ class SignupPage extends React.Component {
|
||||
}}
|
||||
onFocus={() => {
|
||||
this.setState({
|
||||
passwordPopoverOpen: true,
|
||||
passwordPopoverOpen: application.organizationObj.passwordOptions?.length > 0,
|
||||
passwordPopover: PasswordChecker.renderPasswordPopover(application.organizationObj.passwordOptions, this.form.current?.getFieldValue("password") ?? ""),
|
||||
});
|
||||
}}
|
||||
|
@ -132,18 +132,18 @@ export const PasswordModal = (props) => {
|
||||
</Row>
|
||||
) : null}
|
||||
<Row style={{width: "100%", marginBottom: "20px"}}>
|
||||
<Popover placement="right" content={passwordPopover} open={passwordPopoverOpen}>
|
||||
<Popover placement={window.innerWidth >= 960 ? "right" : "top"} content={passwordPopover} open={passwordPopoverOpen}>
|
||||
<Input.Password
|
||||
addonBefore={i18next.t("user:New Password")}
|
||||
placeholder={i18next.t("user:input password")}
|
||||
onChange={(e) => {
|
||||
handleNewPassword(e.target.value);
|
||||
setPasswordPopoverOpen(true);
|
||||
setPasswordPopoverOpen(passwordOptions?.length > 0);
|
||||
setPasswordPopover(PasswordChecker.renderPasswordPopover(passwordOptions, e.target.value));
|
||||
|
||||
}}
|
||||
onFocus={() => {
|
||||
setPasswordPopoverOpen(true);
|
||||
setPasswordPopoverOpen(passwordOptions?.length > 0);
|
||||
setPasswordPopover(PasswordChecker.renderPasswordPopover(passwordOptions, newPassword));
|
||||
}}
|
||||
onBlur={() => {
|
||||
|
Reference in New Issue
Block a user