Skip to content

Commit

Permalink
chore(style): use gofumpt to fmt go code (casdoor#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxi0410 authored Aug 7, 2022
1 parent 45d2745 commit 2ea58cd
Show file tree
Hide file tree
Showing 63 changed files with 172 additions and 188 deletions.
2 changes: 1 addition & 1 deletion authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ m = (r.subOwner == p.subOwner || p.subOwner == "*") && \

Enforcer.ClearPolicy()

//if len(Enforcer.GetPolicy()) == 0 {
// if len(Enforcer.GetPolicy()) == 0 {
if true {
ruleText := `
p, built-in, *, *, *, *, *
Expand Down
3 changes: 1 addition & 2 deletions captcha/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import (

const AliyunCaptchaVerifyUrl = "http://afs.aliyuncs.com"

type AliyunCaptchaProvider struct {
}
type AliyunCaptchaProvider struct{}

func NewAliyunCaptchaProvider() *AliyunCaptchaProvider {
captcha := &AliyunCaptchaProvider{}
Expand Down
3 changes: 1 addition & 2 deletions captcha/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ package captcha

import "github.com/casdoor/casdoor/object"

type DefaultCaptchaProvider struct {
}
type DefaultCaptchaProvider struct{}

func NewDefaultCaptchaProvider() *DefaultCaptchaProvider {
captcha := &DefaultCaptchaProvider{}
Expand Down
3 changes: 1 addition & 2 deletions captcha/geetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (

const GEETESTCaptchaVerifyUrl = "http://gcaptcha4.geetest.com/validate"

type GEETESTCaptchaProvider struct {
}
type GEETESTCaptchaProvider struct{}

func NewGEETESTCaptchaProvider() *GEETESTCaptchaProvider {
captcha := &GEETESTCaptchaProvider{}
Expand Down
3 changes: 1 addition & 2 deletions captcha/hcaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (

const HCaptchaVerifyUrl = "https://hcaptcha.com/siteverify"

type HCaptchaProvider struct {
}
type HCaptchaProvider struct{}

func NewHCaptchaProvider() *HCaptchaProvider {
captcha := &HCaptchaProvider{}
Expand Down
3 changes: 1 addition & 2 deletions captcha/recaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (

const ReCaptchaVerifyUrl = "https://recaptcha.net/recaptcha/api/siteverify"

type ReCaptchaProvider struct {
}
type ReCaptchaProvider struct{}

func NewReCaptchaProvider() *ReCaptchaProvider {
captcha := &ReCaptchaProvider{}
Expand Down
4 changes: 2 additions & 2 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func GetConfigInt64(key string) (int64, error) {
}

func init() {
//this array contains the beego configuration items that may be modified via env
var presetConfigItems = []string{"httpport", "appname"}
// this array contains the beego configuration items that may be modified via env
presetConfigItems := []string{"httpport", "appname"}
for _, key := range presetConfigItems {
if value, ok := os.LookupEnv(key); ok {
beego.AppConfig.Set(key, value)
Expand Down
4 changes: 2 additions & 2 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestGetConfString(t *testing.T) {
{"Should be return value", "key", "value"},
}

//do some set up job
// do some set up job

os.Setenv("appname", "casbin")
os.Setenv("key", "value")
Expand All @@ -58,7 +58,7 @@ func TestGetConfInt(t *testing.T) {
{"Should be return 8000", "verificationCodeTimeout", 10},
}

//do some set up job
// do some set up job
os.Setenv("httpport", "8001")

err := beego.LoadAppConfig("ini", "app.conf")
Expand Down
8 changes: 3 additions & 5 deletions controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func tokenToResponse(token *object.Token) *Response {
return &Response{Status: "error", Msg: "fail to get accessToken", Data: token.AccessToken}
}
return &Response{Status: "ok", Msg: "", Data: token.AccessToken}

}

// HandleLoggedIn ...
Expand Down Expand Up @@ -86,15 +85,14 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
// The prompt page needs the user to be signed in
c.SetSessionUsername(userId)
}
} else if form.Type == ResponseTypeToken || form.Type == ResponseTypeIdToken { //implicit flow
} else if form.Type == ResponseTypeToken || form.Type == ResponseTypeIdToken { // implicit flow
if !object.IsGrantTypeValid(form.Type, application.GrantTypes) {
resp = &Response{Status: "error", Msg: fmt.Sprintf("error: grant_type: %s is not supported in this application", form.Type), Data: ""}
} else {
scope := c.Input().Get("scope")
token, _ := object.GetTokenByUser(application, user, scope, c.Ctx.Request.Host)
resp = tokenToResponse(token)
}

} else if form.Type == ResponseTypeSaml { // saml flow
res, redirectUrl, err := object.GetSamlResponse(application, user, form.SamlRequest, c.Ctx.Request.Host)
if err != nil {
Expand All @@ -103,7 +101,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
}
resp = &Response{Status: "ok", Msg: "", Data: res, Data2: redirectUrl}
} else if form.Type == ResponseTypeCas {
//not oauth but CAS SSO protocol
// not oauth but CAS SSO protocol
service := c.Input().Get("service")
resp = wrapErrorResponse(nil)
if service != "" {
Expand Down Expand Up @@ -430,7 +428,7 @@ func (c *ApiController) Login() {
} else if provider.Category == "SAML" {
resp = &Response{Status: "error", Msg: "The account does not exist"}
}
//resp = &Response{Status: "ok", Msg: "", Data: res}
// resp = &Response{Status: "ok", Msg: "", Data: res}
} else { // form.Method != "signup"
userId := c.GetSessionUsername()
if userId == "" {
Expand Down
24 changes: 11 additions & 13 deletions controllers/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ func (c *RootController) CasValidate() {
return
}
if ok, response, issuedService, _ := object.GetCasTokenByTicket(ticket); ok {
//check whether service is the one for which we previously issued token
// check whether service is the one for which we previously issued token
if issuedService == service {
c.Ctx.Output.Body([]byte(fmt.Sprintf("yes\n%s\n", response.User)))
return
}

}
//token not found
// token not found
c.Ctx.Output.Body([]byte("no\n"))
}

Expand Down Expand Up @@ -83,39 +82,39 @@ func (c *RootController) CasP3ServiceAndProxyValidate() {
Xmlns: "http://www.yale.edu/tp/cas",
}

//check whether all required parameters are met
// check whether all required parameters are met
if service == "" || ticket == "" {
c.sendCasAuthenticationResponseErr(InvalidRequest, "service and ticket must exist", format)
return
}
ok, response, issuedService, userId := object.GetCasTokenByTicket(ticket)
//find the token
// find the token
if ok {
//check whether service is the one for which we previously issued token
// check whether service is the one for which we previously issued token
if strings.HasPrefix(service, issuedService) {
serviceResponse.Success = response
} else {
//service not match
// service not match
c.sendCasAuthenticationResponseErr(InvalidService, fmt.Sprintf("service %s and %s does not match", service, issuedService), format)
return
}
} else {
//token not found
// token not found
c.sendCasAuthenticationResponseErr(InvalidTicket, fmt.Sprintf("Ticket %s not recognized", ticket), format)
return
}

if pgtUrl != "" && serviceResponse.Failure == nil {
//that means we are in proxy web flow
// that means we are in proxy web flow
pgt := object.StoreCasTokenForPgt(serviceResponse.Success, service, userId)
pgtiou := serviceResponse.Success.ProxyGrantingTicket
//todo: check whether it is https
// todo: check whether it is https
pgtUrlObj, err := url.Parse(pgtUrl)
if pgtUrlObj.Scheme != "https" {
c.sendCasAuthenticationResponseErr(InvalidProxyCallback, "callback is not https", format)
return
}
//make a request to pgturl passing pgt and pgtiou
// make a request to pgturl passing pgt and pgtiou
if err != nil {
c.sendCasAuthenticationResponseErr(InteralError, err.Error(), format)
return
Expand All @@ -133,7 +132,7 @@ func (c *RootController) CasP3ServiceAndProxyValidate() {

resp, err := http.DefaultClient.Do(request)
if err != nil || !(resp.StatusCode >= 200 && resp.StatusCode < 400) {
//failed to send request
// failed to send request
c.sendCasAuthenticationResponseErr(InvalidProxyCallback, err.Error(), format)
return
}
Expand Down Expand Up @@ -184,7 +183,6 @@ func (c *RootController) CasProxy() {
c.Data["xml"] = serviceResponse
c.ServeXML()
}

}

func (c *RootController) SamlValidate() {
Expand Down
4 changes: 2 additions & 2 deletions controllers/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type LdapServer struct {
}

type LdapResp struct {
//Groups []LdapRespGroup `json:"groups"`
// Groups []LdapRespGroup `json:"groups"`
Users []object.LdapRespUser `json:"users"`
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *ApiController) GetLdapUser() {
Uid: user.Uid,
Cn: user.Cn,
GroupId: user.GidNumber,
//GroupName: groupsMap[user.GidNumber].Cn,
// GroupName: groupsMap[user.GidNumber].Cn,
Uuid: user.Uuid,
Email: util.GetMaxLenStr(user.Mail, user.Email, user.EmailAddress),
Phone: util.GetMaxLenStr(user.TelephoneNumber, user.Mobile, user.MobileTelephoneNumber),
Expand Down
1 change: 1 addition & 0 deletions controllers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package controllers

import (
"encoding/json"

"github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util"
Expand Down
1 change: 1 addition & 0 deletions controllers/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package controllers

import (
"encoding/json"

"github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util"
Expand Down
1 change: 0 additions & 1 deletion cred/argon2id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func NewArgon2idCredManager() *Argon2idCredManager {
}

func (cm *Argon2idCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string {

hash, err := argon2id.CreateHash(password, argon2id.DefaultParams)
if err != nil {
return ""
Expand Down
3 changes: 2 additions & 1 deletion cred/pbkdf2-salt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cred
import (
"crypto/sha256"
"encoding/base64"

"golang.org/x/crypto/pbkdf2"
)

Expand All @@ -36,4 +37,4 @@ func (cm *Pbkdf2SaltCredManager) GetHashedPassword(password string, userSalt str

func (cm *Pbkdf2SaltCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool {
return hashedPwd == cm.GetHashedPassword(plainPwd, userSalt, organizationSalt)
}
}
4 changes: 2 additions & 2 deletions idp/adfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (idp *AdfsIdProvider) SetHttpClient(client *http.Client) {
}

func (idp *AdfsIdProvider) getConfig(hostUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{
endpoint := oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/adfs/oauth2/authorize", hostUrl),
TokenURL: fmt.Sprintf("%s/adfs/oauth2/token", hostUrl),
}

var config = &oauth2.Config{
config := &oauth2.Config{
Endpoint: endpoint,
}

Expand Down
5 changes: 2 additions & 3 deletions idp/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func (idp *AlipayIdProvider) SetHttpClient(client *http.Client) {

// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *AlipayIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{
endpoint := oauth2.Endpoint{
AuthURL: "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm",
TokenURL: "https://openapi.alipay.com/gateway.do",
}

var config = &oauth2.Config{
config := &oauth2.Config{
Scopes: []string{"", ""},
Endpoint: endpoint,
ClientID: clientId,
Expand Down Expand Up @@ -206,7 +206,6 @@ func (idp *AlipayIdProvider) postWithBody(body interface{}, targetUrl string) ([
return nil, err
}
data, err := ioutil.ReadAll(resp.Body)

if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions idp/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func (idp *BaiduIdProvider) SetHttpClient(client *http.Client) {
}

func (idp *BaiduIdProvider) getConfig() *oauth2.Config {
var endpoint = oauth2.Endpoint{
endpoint := oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
}

var config = &oauth2.Config{
config := &oauth2.Config{
Scopes: []string{"email"},
Endpoint: endpoint,
}
Expand Down
6 changes: 2 additions & 4 deletions idp/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (idp *BilibiliIdProvider) SetHttpClient(client *http.Client) {

// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *BilibiliIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{
endpoint := oauth2.Endpoint{
TokenURL: "https://api.bilibili.com/x/account-oauth2/v1/token",
AuthURL: "http://member.bilibili.com/arcopen/fn/user/account/info",
}

var config = &oauth2.Config{
config := &oauth2.Config{
Scopes: []string{"", ""},
Endpoint: endpoint,
ClientID: clientId,
Expand Down Expand Up @@ -104,7 +104,6 @@ func (idp *BilibiliIdProvider) GetToken(code string) (*oauth2.Token, error) {
}

data, err := idp.postWithBody(pTokenParams, idp.Config.Endpoint.TokenURL)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -167,7 +166,6 @@ func (idp *BilibiliIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
userInfoUrl := fmt.Sprintf("%s?%s", idp.Config.Endpoint.AuthURL, params.Encode())

resp, err := idp.Client.Get(userInfoUrl)

if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions idp/casdoor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)

if err != nil {
return nil, err
}
Expand All @@ -82,7 +81,7 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
return nil, err
}

//check if token is expired
// check if token is expired
if pToken.ExpiresIn <= 0 {
return nil, fmt.Errorf("%s", pToken.AccessToken)
}
Expand All @@ -91,7 +90,6 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
Expiry: time.Unix(time.Now().Unix()+int64(pToken.ExpiresIn), 0),
}
return token, nil

}

/*
Expand Down Expand Up @@ -125,7 +123,7 @@ func (idp *CasdoorIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error
if err != nil {
return nil, err
}
//add accesstoken to bearer token
// add accesstoken to bearer token
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
resp, err := idp.Client.Do(request)
if err != nil {
Expand Down Expand Up @@ -155,5 +153,4 @@ func (idp *CasdoorIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error
AvatarUrl: cdUserinfo.AvatarUrl,
}
return userInfo, nil

}
Loading

0 comments on commit 2ea58cd

Please sign in to comment.