id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
14,000
itsyouonline/identityserver
oauthservice/jwt.go
getGrants
func getGrants(username, clientID string, r *http.Request) ([]string, error) { // Add grants grantMgr := grants.NewManager(r) rawGrants, err := grantMgr.GetGrantsForUser(username, clientID) if err != nil && !db.IsNotFound(err) { return nil, err } if err != nil { rawGrants = &grants.SavedGrants{Grants: []grants.Grant{}} } fullGrants := make([]string, len(rawGrants.Grants)) for i, g := range rawGrants.Grants { fullGrants[i] = grants.FullName(g) } log.Debug("Found ", len(fullGrants), " grant(s)") return fullGrants, nil }
go
func getGrants(username, clientID string, r *http.Request) ([]string, error) { // Add grants grantMgr := grants.NewManager(r) rawGrants, err := grantMgr.GetGrantsForUser(username, clientID) if err != nil && !db.IsNotFound(err) { return nil, err } if err != nil { rawGrants = &grants.SavedGrants{Grants: []grants.Grant{}} } fullGrants := make([]string, len(rawGrants.Grants)) for i, g := range rawGrants.Grants { fullGrants[i] = grants.FullName(g) } log.Debug("Found ", len(fullGrants), " grant(s)") return fullGrants, nil }
[ "func", "getGrants", "(", "username", ",", "clientID", "string", ",", "r", "*", "http", ".", "Request", ")", "(", "[", "]", "string", ",", "error", ")", "{", "// Add grants", "grantMgr", ":=", "grants", ".", "NewManager", "(", "r", ")", "\n", "rawGrant...
// getGrants returns a list of all the grants for a user
[ "getGrants", "returns", "a", "list", "of", "all", "the", "grants", "for", "a", "user" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/jwt.go#L626-L645
14,001
itsyouonline/identityserver
tools/translations.go
loadTranslationTemplates
func loadTranslationTemplates(rawKey string) (tt translationTemplates, err error) { langKey := parseLangKey(rawKey) assetName := "i18n/" + langKey + ".json" translationFile, err := templates.Asset(assetName) // translation file doesn't exis, or there is an error loading it if err != nil { // try and use the default translations translationFile, err = templates.Asset(defaultTranslations) if err != nil { log.Error("Error while loading translations: ", err) } } err = json.NewDecoder(bytes.NewReader(translationFile)).Decode(&tt) return }
go
func loadTranslationTemplates(rawKey string) (tt translationTemplates, err error) { langKey := parseLangKey(rawKey) assetName := "i18n/" + langKey + ".json" translationFile, err := templates.Asset(assetName) // translation file doesn't exis, or there is an error loading it if err != nil { // try and use the default translations translationFile, err = templates.Asset(defaultTranslations) if err != nil { log.Error("Error while loading translations: ", err) } } err = json.NewDecoder(bytes.NewReader(translationFile)).Decode(&tt) return }
[ "func", "loadTranslationTemplates", "(", "rawKey", "string", ")", "(", "tt", "translationTemplates", ",", "err", "error", ")", "{", "langKey", ":=", "parseLangKey", "(", "rawKey", ")", "\n", "assetName", ":=", "\"", "\"", "+", "langKey", "+", "\"", "\"", "...
// loadTranslationTemplates tries to load a translation file
[ "loadTranslationTemplates", "tries", "to", "load", "a", "translation", "file" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/tools/translations.go#L26-L40
14,002
itsyouonline/identityserver
tools/translations.go
ParseTranslations
func ParseTranslations(rawKey string, tv TranslationValues) (translations Translations, err error) { // Load the translation templates from the file tt, err := loadTranslationTemplates(rawKey) if err != nil { log.Error("Error while parsing translations - Failed to load translations: ", err) return } translations = make(Translations) templateEngine := template.New("translations") buf := new(bytes.Buffer) // Iterate over the keys and values provided to render for key, value := range tv { // If a translation key is provided that does not exist in the file consider it an error template, exists := tt[key] if !exists { log.Error("Error while parsing translations - Trying to render an unexisting key: ", err) return } // If no translation values are provided, store the raw template (could be that there // are no values required for this template). if value == nil { translations[key] = template continue } // Make sure the buffer is empty buf.Reset() // Parse the template string in the template engine and render it in the buffer templateEngine.Parse(template) err = templateEngine.Execute(buf, value) if err != nil { log.Error("Error while parsing translations - Failed to render template: ", err) return } translations[key] = buf.String() } return }
go
func ParseTranslations(rawKey string, tv TranslationValues) (translations Translations, err error) { // Load the translation templates from the file tt, err := loadTranslationTemplates(rawKey) if err != nil { log.Error("Error while parsing translations - Failed to load translations: ", err) return } translations = make(Translations) templateEngine := template.New("translations") buf := new(bytes.Buffer) // Iterate over the keys and values provided to render for key, value := range tv { // If a translation key is provided that does not exist in the file consider it an error template, exists := tt[key] if !exists { log.Error("Error while parsing translations - Trying to render an unexisting key: ", err) return } // If no translation values are provided, store the raw template (could be that there // are no values required for this template). if value == nil { translations[key] = template continue } // Make sure the buffer is empty buf.Reset() // Parse the template string in the template engine and render it in the buffer templateEngine.Parse(template) err = templateEngine.Execute(buf, value) if err != nil { log.Error("Error while parsing translations - Failed to render template: ", err) return } translations[key] = buf.String() } return }
[ "func", "ParseTranslations", "(", "rawKey", "string", ",", "tv", "TranslationValues", ")", "(", "translations", "Translations", ",", "err", "error", ")", "{", "// Load the translation templates from the file", "tt", ",", "err", ":=", "loadTranslationTemplates", "(", "...
// Parse translations loads the translation templates and renders them with the // provided values
[ "Parse", "translations", "loads", "the", "translation", "templates", "and", "renders", "them", "with", "the", "provided", "values" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/tools/translations.go#L44-L80
14,003
itsyouonline/identityserver
oauthservice/oidc.go
getIDTokenFromCode
func getIDTokenFromCode(code string, jwtSigningKey *ecdsa.PrivateKey, r *http.Request, at *AccessToken, mgr *Manager) (string, int) { // get scopes fmt.Println(at.Scope) ar, err := mgr.getAuthorizationRequest(code) if err != nil { log.Debugf("something went wrong getting authorize request for the ID token: %s", err) return "", http.StatusInternalServerError } scopeStr := ar.Scope if !scopePresent(scopeStr, scopeOpenID) { return "", http.StatusOK } token, err := getIDTokenStr(jwtSigningKey, r, at, scopeStr) if err != nil { log.Debugf("something went wrong getting ID token: %s", err) return "", http.StatusBadRequest } return token, http.StatusOK }
go
func getIDTokenFromCode(code string, jwtSigningKey *ecdsa.PrivateKey, r *http.Request, at *AccessToken, mgr *Manager) (string, int) { // get scopes fmt.Println(at.Scope) ar, err := mgr.getAuthorizationRequest(code) if err != nil { log.Debugf("something went wrong getting authorize request for the ID token: %s", err) return "", http.StatusInternalServerError } scopeStr := ar.Scope if !scopePresent(scopeStr, scopeOpenID) { return "", http.StatusOK } token, err := getIDTokenStr(jwtSigningKey, r, at, scopeStr) if err != nil { log.Debugf("something went wrong getting ID token: %s", err) return "", http.StatusBadRequest } return token, http.StatusOK }
[ "func", "getIDTokenFromCode", "(", "code", "string", ",", "jwtSigningKey", "*", "ecdsa", ".", "PrivateKey", ",", "r", "*", "http", ".", "Request", ",", "at", "*", "AccessToken", ",", "mgr", "*", "Manager", ")", "(", "string", ",", "int", ")", "{", "// ...
// getIDTokenFromCode returns an ID token if scopes associated with the code match // the OpenId scope // If no openId scope is found, the returned string is empty // if no error, the int returned represents http.StatusOK
[ "getIDTokenFromCode", "returns", "an", "ID", "token", "if", "scopes", "associated", "with", "the", "code", "match", "the", "OpenId", "scope", "If", "no", "openId", "scope", "is", "found", "the", "returned", "string", "is", "empty", "if", "no", "error", "the"...
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/oidc.go#L23-L44
14,004
itsyouonline/identityserver
oauthservice/oidc.go
scopePresent
func scopePresent(scopeStr string, scopeToSearch string) bool { scopeSlice := strings.Split(scopeStr, ",") for _, scope := range scopeSlice { if scope == scopeToSearch { return true } } return false }
go
func scopePresent(scopeStr string, scopeToSearch string) bool { scopeSlice := strings.Split(scopeStr, ",") for _, scope := range scopeSlice { if scope == scopeToSearch { return true } } return false }
[ "func", "scopePresent", "(", "scopeStr", "string", ",", "scopeToSearch", "string", ")", "bool", "{", "scopeSlice", ":=", "strings", ".", "Split", "(", "scopeStr", ",", "\"", "\"", ")", "\n", "for", "_", ",", "scope", ":=", "range", "scopeSlice", "{", "if...
// scopePresent returns true if scope is in the scope string // The scope string is expected to be a comma seperated list of scopes
[ "scopePresent", "returns", "true", "if", "scope", "is", "in", "the", "scope", "string", "The", "scope", "string", "is", "expected", "to", "be", "a", "comma", "seperated", "list", "of", "scopes" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/oidc.go#L48-L57
14,005
itsyouonline/identityserver
oauthservice/oidc.go
getIDTokenStr
func getIDTokenStr(jwtSigningKey *ecdsa.PrivateKey, r *http.Request, at *AccessToken, scopeStr string) (string, error) { // for each valid oidc standard scope, fetch related data token := jwt.New(jwt.SigningMethodES384) // setup basic claims token.Claims["sub"] = at.Username token.Claims["iss"] = issuer token.Claims["iat"] = at.CreatedAt.Unix() token.Claims["exp"] = at.ExpirationTime().Unix() token.Claims["aud"] = at.ClientID // check scopes for additional claims err := setValuesFromScope(token, scopeStr, r, at) if err != nil { return "", fmt.Errorf("failed to get additional claims for id token: %s", err) } return token.SignedString(jwtSigningKey) }
go
func getIDTokenStr(jwtSigningKey *ecdsa.PrivateKey, r *http.Request, at *AccessToken, scopeStr string) (string, error) { // for each valid oidc standard scope, fetch related data token := jwt.New(jwt.SigningMethodES384) // setup basic claims token.Claims["sub"] = at.Username token.Claims["iss"] = issuer token.Claims["iat"] = at.CreatedAt.Unix() token.Claims["exp"] = at.ExpirationTime().Unix() token.Claims["aud"] = at.ClientID // check scopes for additional claims err := setValuesFromScope(token, scopeStr, r, at) if err != nil { return "", fmt.Errorf("failed to get additional claims for id token: %s", err) } return token.SignedString(jwtSigningKey) }
[ "func", "getIDTokenStr", "(", "jwtSigningKey", "*", "ecdsa", ".", "PrivateKey", ",", "r", "*", "http", ".", "Request", ",", "at", "*", "AccessToken", ",", "scopeStr", "string", ")", "(", "string", ",", "error", ")", "{", "// for each valid oidc standard scope,...
// getIDTokenStr returns an oidc ID token string // It will set the default required claims // and calls setValuesFromScope to set additional claims
[ "getIDTokenStr", "returns", "an", "oidc", "ID", "token", "string", "It", "will", "set", "the", "default", "required", "claims", "and", "calls", "setValuesFromScope", "to", "set", "additional", "claims" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/oidc.go#L62-L80
14,006
itsyouonline/identityserver
oauthservice/oidc.go
setValuesFromScope
func setValuesFromScope(token *jwt.Token, scopeStr string, r *http.Request, at *AccessToken) error { userMgr := user.NewManager(r) authorization, err := userMgr.GetAuthorization(at.Username, at.ClientID) if err != nil { return fmt.Errorf("failed to get authorization: %s", err) } userObj, err := userMgr.GetByName(at.Username) if err != nil { return fmt.Errorf("failed to get user: %s", err) } scopeSlice := strings.Split(scopeStr, ",") for _, scope := range scopeSlice { switch { case scope == "user:name": token.Claims[scope] = fmt.Sprintf("%s %s", userObj.Firstname, userObj.Lastname) case strings.HasPrefix(scope, "user:email"): requestedLabel := strings.TrimPrefix(scope, "user:email") if requestedLabel == "" || requestedLabel == "user:email" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "email", authorization) email, err := userObj.GetEmailAddressByLabel(label) if err != nil { return fmt.Errorf("could not get user's email: %s", err) } token.Claims[scope] = email.EmailAddress case strings.HasPrefix(scope, "user:validated:email"): requestedLabel := strings.TrimPrefix(scope, "user:validated:email") if requestedLabel == "" || requestedLabel == "user:validated:email" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "validatedemail", authorization) email, err := userObj.GetEmailAddressByLabel(label) if err != nil { return fmt.Errorf("could not get user's email: %s", err) } token.Claims[scope] = email.EmailAddress case strings.HasPrefix(scope, "user:phone"): requestedLabel := strings.TrimPrefix(scope, "user:phone:") if requestedLabel == "" || requestedLabel == "user:phone" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "phone", authorization) phone, err := userObj.GetPhonenumberByLabel(label) if err != nil { return fmt.Errorf("could not get user's phone: %s", err) } token.Claims[scope] = phone.Phonenumber case strings.HasPrefix(scope, "user:validated:phone"): requestedLabel := strings.TrimPrefix(scope, "user:validated:phone:") if requestedLabel == "" || requestedLabel == "user:validated:phone" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "validatedphone", authorization) phone, err := userObj.GetPhonenumberByLabel(label) if err != nil { return fmt.Errorf("could not get user's phone: %s", err) } token.Claims[scope] = phone.Phonenumber } } return nil }
go
func setValuesFromScope(token *jwt.Token, scopeStr string, r *http.Request, at *AccessToken) error { userMgr := user.NewManager(r) authorization, err := userMgr.GetAuthorization(at.Username, at.ClientID) if err != nil { return fmt.Errorf("failed to get authorization: %s", err) } userObj, err := userMgr.GetByName(at.Username) if err != nil { return fmt.Errorf("failed to get user: %s", err) } scopeSlice := strings.Split(scopeStr, ",") for _, scope := range scopeSlice { switch { case scope == "user:name": token.Claims[scope] = fmt.Sprintf("%s %s", userObj.Firstname, userObj.Lastname) case strings.HasPrefix(scope, "user:email"): requestedLabel := strings.TrimPrefix(scope, "user:email") if requestedLabel == "" || requestedLabel == "user:email" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "email", authorization) email, err := userObj.GetEmailAddressByLabel(label) if err != nil { return fmt.Errorf("could not get user's email: %s", err) } token.Claims[scope] = email.EmailAddress case strings.HasPrefix(scope, "user:validated:email"): requestedLabel := strings.TrimPrefix(scope, "user:validated:email") if requestedLabel == "" || requestedLabel == "user:validated:email" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "validatedemail", authorization) email, err := userObj.GetEmailAddressByLabel(label) if err != nil { return fmt.Errorf("could not get user's email: %s", err) } token.Claims[scope] = email.EmailAddress case strings.HasPrefix(scope, "user:phone"): requestedLabel := strings.TrimPrefix(scope, "user:phone:") if requestedLabel == "" || requestedLabel == "user:phone" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "phone", authorization) phone, err := userObj.GetPhonenumberByLabel(label) if err != nil { return fmt.Errorf("could not get user's phone: %s", err) } token.Claims[scope] = phone.Phonenumber case strings.HasPrefix(scope, "user:validated:phone"): requestedLabel := strings.TrimPrefix(scope, "user:validated:phone:") if requestedLabel == "" || requestedLabel == "user:validated:phone" { requestedLabel = "main" } label := getRealLabel(requestedLabel, "validatedphone", authorization) phone, err := userObj.GetPhonenumberByLabel(label) if err != nil { return fmt.Errorf("could not get user's phone: %s", err) } token.Claims[scope] = phone.Phonenumber } } return nil }
[ "func", "setValuesFromScope", "(", "token", "*", "jwt", ".", "Token", ",", "scopeStr", "string", ",", "r", "*", "http", ".", "Request", ",", "at", "*", "AccessToken", ")", "error", "{", "userMgr", ":=", "user", ".", "NewManager", "(", "r", ")", "\n", ...
// setValuesFromScope check the scopes for additional claims to be added to the provided token
[ "setValuesFromScope", "check", "the", "scopes", "for", "additional", "claims", "to", "be", "added", "to", "the", "provided", "token" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/oauthservice/oidc.go#L83-L147
14,007
itsyouonline/identityserver
db/init.go
Connect
func Connect(url string) { if dbSession != nil { return } for { err := initializeDB(url) if err == nil { break } log.Debugf("Failed to connect to DB (%s), retrying in 5 seconds...", url) time.Sleep(5 * time.Second) } log.Info("Initialized mongo connection") }
go
func Connect(url string) { if dbSession != nil { return } for { err := initializeDB(url) if err == nil { break } log.Debugf("Failed to connect to DB (%s), retrying in 5 seconds...", url) time.Sleep(5 * time.Second) } log.Info("Initialized mongo connection") }
[ "func", "Connect", "(", "url", "string", ")", "{", "if", "dbSession", "!=", "nil", "{", "return", "\n", "}", "\n\n", "for", "{", "err", ":=", "initializeDB", "(", "url", ")", "\n", "if", "err", "==", "nil", "{", "break", "\n", "}", "\n", "log", "...
// Connect ensures a mongo DB connection is initialized.
[ "Connect", "ensures", "a", "mongo", "DB", "connection", "is", "initialized", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/init.go#L31-L46
14,008
itsyouonline/identityserver
siteservice/session.go
initializeSessionStore
func initializeSessionStore(cookieSecret string, maxAge int) (sessionStore *sessions.CookieStore) { sessionStore = sessions.NewCookieStore([]byte(cookieSecret)) sessionStore.Options.HttpOnly = true sessionStore.Options.Secure = true sessionStore.Options.MaxAge = maxAge return }
go
func initializeSessionStore(cookieSecret string, maxAge int) (sessionStore *sessions.CookieStore) { sessionStore = sessions.NewCookieStore([]byte(cookieSecret)) sessionStore.Options.HttpOnly = true sessionStore.Options.Secure = true sessionStore.Options.MaxAge = maxAge return }
[ "func", "initializeSessionStore", "(", "cookieSecret", "string", ",", "maxAge", "int", ")", "(", "sessionStore", "*", "sessions", ".", "CookieStore", ")", "{", "sessionStore", "=", "sessions", ".", "NewCookieStore", "(", "[", "]", "byte", "(", "cookieSecret", ...
//initializeSessionStore creates a cookieStore // mageAge is the maximum age in seconds
[ "initializeSessionStore", "creates", "a", "cookieStore", "mageAge", "is", "the", "maximum", "age", "in", "seconds" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L31-L38
14,009
itsyouonline/identityserver
siteservice/session.go
GetSession
func (service *Service) GetSession(request *http.Request, kind SessionType, name string) (*sessions.Session, error) { return service.Sessions[kind].Get(request, name) }
go
func (service *Service) GetSession(request *http.Request, kind SessionType, name string) (*sessions.Session, error) { return service.Sessions[kind].Get(request, name) }
[ "func", "(", "service", "*", "Service", ")", "GetSession", "(", "request", "*", "http", ".", "Request", ",", "kind", "SessionType", ",", "name", "string", ")", "(", "*", "sessions", ".", "Session", ",", "error", ")", "{", "return", "service", ".", "Ses...
//GetSession returns the a session of the specified kind and a specific name
[ "GetSession", "returns", "the", "a", "session", "of", "the", "specified", "kind", "and", "a", "specific", "name" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L51-L53
14,010
itsyouonline/identityserver
siteservice/session.go
SetLoggedInUser
func (service *Service) SetLoggedInUser(w http.ResponseWriter, request *http.Request, username string) (err error) { authenticatedSession, err := service.GetSession(request, SessionInteractive, "authenticatedsession") if err != nil { log.Error(err) return } authenticatedSession.Values["username"] = username //TODO: rework this, is not really secure I think // Set user cookie after successful login // base64 encode the username. Use standard encoding to enable decoding by native javascript // functions cookie := &http.Cookie{ Name: "itsyou.online.user", Path: "/", Value: base64.StdEncoding.EncodeToString([]byte(username)), } http.SetCookie(w, cookie) // Clear login session loginCookie := &http.Cookie{ Name: "loginsession", Path: "/", Value: "", Expires: time.Unix(1, 0), } http.SetCookie(w, loginCookie) return }
go
func (service *Service) SetLoggedInUser(w http.ResponseWriter, request *http.Request, username string) (err error) { authenticatedSession, err := service.GetSession(request, SessionInteractive, "authenticatedsession") if err != nil { log.Error(err) return } authenticatedSession.Values["username"] = username //TODO: rework this, is not really secure I think // Set user cookie after successful login // base64 encode the username. Use standard encoding to enable decoding by native javascript // functions cookie := &http.Cookie{ Name: "itsyou.online.user", Path: "/", Value: base64.StdEncoding.EncodeToString([]byte(username)), } http.SetCookie(w, cookie) // Clear login session loginCookie := &http.Cookie{ Name: "loginsession", Path: "/", Value: "", Expires: time.Unix(1, 0), } http.SetCookie(w, loginCookie) return }
[ "func", "(", "service", "*", "Service", ")", "SetLoggedInUser", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ",", "username", "string", ")", "(", "err", "error", ")", "{", "authenticatedSession", ",", "err", ":=", ...
//SetLoggedInUser creates a session for an authenticated user and clears the login session
[ "SetLoggedInUser", "creates", "a", "session", "for", "an", "authenticated", "user", "and", "clears", "the", "login", "session" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L56-L85
14,011
itsyouonline/identityserver
siteservice/session.go
SetLoggedInOauthUser
func (service *Service) SetLoggedInOauthUser(w http.ResponseWriter, r *http.Request, username /*, clientId, state*/ string) (err error) { oauthSession, err := service.GetSession(r, SessionOauth, "oauthsession") if err != nil { log.Error(err) return } oauthSession.Values["username"] = username // No need to set a user cookie since we don't pass through the UI // Clear login session loginCookie := &http.Cookie{ Name: "loginsession", Path: "/", Value: "", Expires: time.Unix(1, 0), } http.SetCookie(w, loginCookie) return }
go
func (service *Service) SetLoggedInOauthUser(w http.ResponseWriter, r *http.Request, username /*, clientId, state*/ string) (err error) { oauthSession, err := service.GetSession(r, SessionOauth, "oauthsession") if err != nil { log.Error(err) return } oauthSession.Values["username"] = username // No need to set a user cookie since we don't pass through the UI // Clear login session loginCookie := &http.Cookie{ Name: "loginsession", Path: "/", Value: "", Expires: time.Unix(1, 0), } http.SetCookie(w, loginCookie) return }
[ "func", "(", "service", "*", "Service", ")", "SetLoggedInOauthUser", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "username", "/*, clientId, state*/", "string", ")", "(", "err", "error", ")", "{", "oauthSession", ",", ...
// SetOauthUser creates a protected session after an oauth flow and clears the login session // Also sets the clientID and state
[ "SetOauthUser", "creates", "a", "protected", "session", "after", "an", "oauth", "flow", "and", "clears", "the", "login", "session", "Also", "sets", "the", "clientID", "and", "state" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L89-L109
14,012
itsyouonline/identityserver
siteservice/session.go
GetLoggedInUser
func (service *Service) GetLoggedInUser(request *http.Request, w http.ResponseWriter) (username string, err error) { authenticatedSession, err := service.GetSession(request, SessionInteractive, "authenticatedsession") if err != nil { log.Error(err) return } err = authenticatedSession.Save(request, w) if err != nil { log.Error(err) return } savedusername := authenticatedSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
go
func (service *Service) GetLoggedInUser(request *http.Request, w http.ResponseWriter) (username string, err error) { authenticatedSession, err := service.GetSession(request, SessionInteractive, "authenticatedsession") if err != nil { log.Error(err) return } err = authenticatedSession.Save(request, w) if err != nil { log.Error(err) return } savedusername := authenticatedSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
[ "func", "(", "service", "*", "Service", ")", "GetLoggedInUser", "(", "request", "*", "http", ".", "Request", ",", "w", "http", ".", "ResponseWriter", ")", "(", "username", "string", ",", "err", "error", ")", "{", "authenticatedSession", ",", "err", ":=", ...
//GetLoggedInUser returns an authenticated user, or an empty string if there is none
[ "GetLoggedInUser", "returns", "an", "authenticated", "user", "or", "an", "empty", "string", "if", "there", "is", "none" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L126-L142
14,013
itsyouonline/identityserver
siteservice/session.go
GetOauthUser
func (service *Service) GetOauthUser(r *http.Request, w http.ResponseWriter) (username string, err error) { oauthSession, err := service.GetSession(r, SessionOauth, "oauthsession") if err != nil { log.Error(err) return } err = oauthSession.Save(r, w) if err != nil { log.Error(err) return } savedusername := oauthSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
go
func (service *Service) GetOauthUser(r *http.Request, w http.ResponseWriter) (username string, err error) { oauthSession, err := service.GetSession(r, SessionOauth, "oauthsession") if err != nil { log.Error(err) return } err = oauthSession.Save(r, w) if err != nil { log.Error(err) return } savedusername := oauthSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
[ "func", "(", "service", "*", "Service", ")", "GetOauthUser", "(", "r", "*", "http", ".", "Request", ",", "w", "http", ".", "ResponseWriter", ")", "(", "username", "string", ",", "err", "error", ")", "{", "oauthSession", ",", "err", ":=", "service", "."...
// GetOauthUser returns the user in an oauth session, or an empty string if there is none
[ "GetOauthUser", "returns", "the", "user", "in", "an", "oauth", "session", "or", "an", "empty", "string", "if", "there", "is", "none" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L145-L161
14,014
itsyouonline/identityserver
siteservice/session.go
SetWebUserMiddleWare
func (service *Service) SetWebUserMiddleWare(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) { if username, err := service.GetLoggedInUser(request, w); err == nil { context.Set(request, "webuser", username) } next.ServeHTTP(w, request) }) }
go
func (service *Service) SetWebUserMiddleWare(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) { if username, err := service.GetLoggedInUser(request, w); err == nil { context.Set(request, "webuser", username) } next.ServeHTTP(w, request) }) }
[ "func", "(", "service", "*", "Service", ")", "SetWebUserMiddleWare", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "...
//SetWebUserMiddleWare puthe the authenticated user on the context
[ "SetWebUserMiddleWare", "puthe", "the", "authenticated", "user", "on", "the", "context" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/session.go#L164-L172
14,015
itsyouonline/identityserver
identityservice/user/users_api.go
filterAuthorizedInfo
func filterAuthorizedInfo(authorizedScopes []string, baseScope string) ([]string, bool) { all := false labels := []string{} for _, scope := range authorizedScopes { if scope == baseScope { all = true continue } if strings.HasPrefix(scope, baseScope) { labels = append(labels, strings.TrimPrefix(scope, baseScope+":")) } } return labels, all }
go
func filterAuthorizedInfo(authorizedScopes []string, baseScope string) ([]string, bool) { all := false labels := []string{} for _, scope := range authorizedScopes { if scope == baseScope { all = true continue } if strings.HasPrefix(scope, baseScope) { labels = append(labels, strings.TrimPrefix(scope, baseScope+":")) } } return labels, all }
[ "func", "filterAuthorizedInfo", "(", "authorizedScopes", "[", "]", "string", ",", "baseScope", "string", ")", "(", "[", "]", "string", ",", "bool", ")", "{", "all", ":=", "false", "\n", "labels", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ...
// filterAuthorizedInfo filters out the labels of a specific scope. If no label is added, we assume all of them are authorized
[ "filterAuthorizedInfo", "filters", "out", "the", "labels", "of", "a", "specific", "scope", ".", "If", "no", "label", "is", "added", "we", "assume", "all", "of", "them", "are", "authorized" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L860-L873
14,016
itsyouonline/identityserver
identityservice/user/users_api.go
FilterValidatedEmails
func FilterValidatedEmails(authorizedMails []user.AuthorizationMap, verifiedMails []user.EmailAddress) []user.AuthorizationMap { var e []user.AuthorizationMap for _, authorizedMail := range authorizedMails { for _, verifiedMail := range verifiedMails { if authorizedMail.RealLabel == verifiedMail.Label { e = append(e, authorizedMail) break } } } return e }
go
func FilterValidatedEmails(authorizedMails []user.AuthorizationMap, verifiedMails []user.EmailAddress) []user.AuthorizationMap { var e []user.AuthorizationMap for _, authorizedMail := range authorizedMails { for _, verifiedMail := range verifiedMails { if authorizedMail.RealLabel == verifiedMail.Label { e = append(e, authorizedMail) break } } } return e }
[ "func", "FilterValidatedEmails", "(", "authorizedMails", "[", "]", "user", ".", "AuthorizationMap", ",", "verifiedMails", "[", "]", "user", ".", "EmailAddress", ")", "[", "]", "user", ".", "AuthorizationMap", "{", "var", "e", "[", "]", "user", ".", "Authoriz...
// FilterValidatedEmail removes email addresses which are not validated
[ "FilterValidatedEmail", "removes", "email", "addresses", "which", "are", "not", "validated" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L1777-L1788
14,017
itsyouonline/identityserver
identityservice/user/users_api.go
FilterValidatedPhones
func FilterValidatedPhones(authorizedPhones []user.AuthorizationMap, verifiedPhones []user.Phonenumber) []user.AuthorizationMap { var p []user.AuthorizationMap for _, authorizedPhone := range authorizedPhones { for _, verifiedPhone := range verifiedPhones { if authorizedPhone.RealLabel == verifiedPhone.Label { p = append(p, authorizedPhone) break } } } return p }
go
func FilterValidatedPhones(authorizedPhones []user.AuthorizationMap, verifiedPhones []user.Phonenumber) []user.AuthorizationMap { var p []user.AuthorizationMap for _, authorizedPhone := range authorizedPhones { for _, verifiedPhone := range verifiedPhones { if authorizedPhone.RealLabel == verifiedPhone.Label { p = append(p, authorizedPhone) break } } } return p }
[ "func", "FilterValidatedPhones", "(", "authorizedPhones", "[", "]", "user", ".", "AuthorizationMap", ",", "verifiedPhones", "[", "]", "user", ".", "Phonenumber", ")", "[", "]", "user", ".", "AuthorizationMap", "{", "var", "p", "[", "]", "user", ".", "Authori...
// FilterValidatedPhones removes phone numbers which are not validated
[ "FilterValidatedPhones", "removes", "phone", "numbers", "which", "are", "not", "validated" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L1791-L1802
14,018
itsyouonline/identityserver
identityservice/user/users_api.go
getRequestingClientFromRequest
func getRequestingClientFromRequest(r *http.Request, w http.ResponseWriter, organizationGlobalID string, allowOnWebsite bool) (string, bool) { requestingClient, validClient := context.Get(r, "client_id").(string) if !validClient { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return requestingClient, false } if requestingClient == "itsyouonline" { if allowOnWebsite { requestingClient = organizationGlobalID } else { // This should never happen as the oauth 2 middleware should give a 403 writeErrorResponse(w, http.StatusBadRequest, "This api call is not available when logged in via the website") return requestingClient, false } } else if requestingClient != organizationGlobalID { writeErrorResponse(w, http.StatusForbidden, "unauthorized_organization") return requestingClient, false } return requestingClient, true }
go
func getRequestingClientFromRequest(r *http.Request, w http.ResponseWriter, organizationGlobalID string, allowOnWebsite bool) (string, bool) { requestingClient, validClient := context.Get(r, "client_id").(string) if !validClient { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return requestingClient, false } if requestingClient == "itsyouonline" { if allowOnWebsite { requestingClient = organizationGlobalID } else { // This should never happen as the oauth 2 middleware should give a 403 writeErrorResponse(w, http.StatusBadRequest, "This api call is not available when logged in via the website") return requestingClient, false } } else if requestingClient != organizationGlobalID { writeErrorResponse(w, http.StatusForbidden, "unauthorized_organization") return requestingClient, false } return requestingClient, true }
[ "func", "getRequestingClientFromRequest", "(", "r", "*", "http", ".", "Request", ",", "w", "http", ".", "ResponseWriter", ",", "organizationGlobalID", "string", ",", "allowOnWebsite", "bool", ")", "(", "string", ",", "bool", ")", "{", "requestingClient", ",", ...
// getRequestingClientFromRequest validates if a see api call is valid for an organization
[ "getRequestingClientFromRequest", "validates", "if", "a", "see", "api", "call", "is", "valid", "for", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2184-L2203
14,019
itsyouonline/identityserver
identityservice/user/users_api.go
AddPublicKey
func (api UsersAPI) AddPublicKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] body := user.PublicKey{} if err := json.NewDecoder(r.Body).Decode(&body); err != nil { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } if !strings.HasPrefix(body.PublicKey, "ssh-rsa AAAAB3NzaC1yc2E") { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } mgr := user.NewManager(r) usr, err := mgr.GetByName(username) if err != nil { if err == mgo.ErrNotFound { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } log.Error("Error while getting user: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } _, err = usr.GetPublicKeyByLabel(body.Label) if err == nil { http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict) return } err = mgr.SavePublicKey(username, body) if err != nil { log.Error("error while saving public key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-type", "application/json") w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(body) }
go
func (api UsersAPI) AddPublicKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] body := user.PublicKey{} if err := json.NewDecoder(r.Body).Decode(&body); err != nil { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } if !strings.HasPrefix(body.PublicKey, "ssh-rsa AAAAB3NzaC1yc2E") { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } mgr := user.NewManager(r) usr, err := mgr.GetByName(username) if err != nil { if err == mgo.ErrNotFound { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } log.Error("Error while getting user: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } _, err = usr.GetPublicKeyByLabel(body.Label) if err == nil { http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict) return } err = mgr.SavePublicKey(username, body) if err != nil { log.Error("error while saving public key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-type", "application/json") w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(body) }
[ "func", "(", "api", "UsersAPI", ")", "AddPublicKey", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "body", ":=", "user", ...
// AddPublicKey Add a public key
[ "AddPublicKey", "Add", "a", "public", "key" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2317-L2359
14,020
itsyouonline/identityserver
identityservice/user/users_api.go
DeletePublicKey
func (api UsersAPI) DeletePublicKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] label := mux.Vars(r)["label"] userMgr := user.NewManager(r) usr, err := userMgr.GetByName(username) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } _, err = usr.GetPublicKeyByLabel(label) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } if err := userMgr.RemovePublicKey(username, label); err != nil { log.Error("ERROR while removing public key:\n", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.WriteHeader(http.StatusNoContent) }
go
func (api UsersAPI) DeletePublicKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] label := mux.Vars(r)["label"] userMgr := user.NewManager(r) usr, err := userMgr.GetByName(username) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } _, err = usr.GetPublicKeyByLabel(label) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } if err := userMgr.RemovePublicKey(username, label); err != nil { log.Error("ERROR while removing public key:\n", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.WriteHeader(http.StatusNoContent) }
[ "func", "(", "api", "UsersAPI", ")", "DeletePublicKey", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "label", ":=", "mux",...
// DeletePublicKey Deletes a public key
[ "DeletePublicKey", "Deletes", "a", "public", "key" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2450-L2474
14,021
itsyouonline/identityserver
identityservice/user/users_api.go
ListPublicKeys
func (api UsersAPI) ListPublicKeys(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] userMgr := user.NewManager(r) userobj, err := userMgr.GetByName(username) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } var publicKeys []user.PublicKey publicKeys = userobj.PublicKeys w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(publicKeys) }
go
func (api UsersAPI) ListPublicKeys(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] userMgr := user.NewManager(r) userobj, err := userMgr.GetByName(username) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } var publicKeys []user.PublicKey publicKeys = userobj.PublicKeys w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(publicKeys) }
[ "func", "(", "api", "UsersAPI", ")", "ListPublicKeys", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "userMgr", ":=", "user...
//ListPublicKeys lists all public keys
[ "ListPublicKeys", "lists", "all", "public", "keys" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2477-L2491
14,022
itsyouonline/identityserver
identityservice/user/users_api.go
GetKeyStore
func (api UsersAPI) GetKeyStore(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) mgr := keystore.NewManager(r) keys, err := mgr.ListKeyStoreKeys(username, globalid) if err != nil && !db.IsNotFound(err) { log.Error("Failed to get keystore keys: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(keys) }
go
func (api UsersAPI) GetKeyStore(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) mgr := keystore.NewManager(r) keys, err := mgr.ListKeyStoreKeys(username, globalid) if err != nil && !db.IsNotFound(err) { log.Error("Failed to get keystore keys: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(keys) }
[ "func", "(", "api", "UsersAPI", ")", "GetKeyStore", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "globalid", ":=", "contex...
// GetKeyStore returns all the publickeys written to the user by an organizaton
[ "GetKeyStore", "returns", "all", "the", "publickeys", "written", "to", "the", "user", "by", "an", "organizaton" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2494-L2508
14,023
itsyouonline/identityserver
identityservice/user/users_api.go
GetKeyStoreKey
func (api UsersAPI) GetKeyStoreKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) label := mux.Vars(r)["label"] mgr := keystore.NewManager(r) key, err := mgr.GetKeyStoreKey(username, globalid, label) if db.IsNotFound(err) { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } if err != nil { log.Error("Failed to get keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(key) }
go
func (api UsersAPI) GetKeyStoreKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) label := mux.Vars(r)["label"] mgr := keystore.NewManager(r) key, err := mgr.GetKeyStoreKey(username, globalid, label) if db.IsNotFound(err) { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return } if err != nil { log.Error("Failed to get keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(key) }
[ "func", "(", "api", "UsersAPI", ")", "GetKeyStoreKey", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "globalid", ":=", "con...
// GetKeyStoreKey returns all specific publickey written to the user by an organizaton
[ "GetKeyStoreKey", "returns", "all", "specific", "publickey", "written", "to", "the", "user", "by", "an", "organizaton" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2511-L2531
14,024
itsyouonline/identityserver
identityservice/user/users_api.go
SaveKeyStoreKey
func (api UsersAPI) SaveKeyStoreKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) body := keystore.KeyStoreKey{} if err := json.NewDecoder(r.Body).Decode(&body); err != nil { log.Debug("Keystore key decoding failed: ", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } // set/update the username and globalid values to those from the authentication body.Username = username body.Globalid = globalid // set the keys timestamp body.KeyData.TimeStamp = db.DateTime(time.Now()) if !body.Validate() { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } mgr := keystore.NewManager(r) // check if this user/organization already has a key under this label if _, err := mgr.GetKeyStoreKey(username, globalid, body.Label); err == nil { http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict) return } err := mgr.Create(&body) if err != nil { log.Error("error while saving keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } key, err := mgr.GetKeyStoreKey(username, globalid, body.Label) if err != nil { log.Error("error while retrieving keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-type", "application/json") w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(key) }
go
func (api UsersAPI) SaveKeyStoreKey(w http.ResponseWriter, r *http.Request) { username := mux.Vars(r)["username"] globalid := context.Get(r, "client_id").(string) body := keystore.KeyStoreKey{} if err := json.NewDecoder(r.Body).Decode(&body); err != nil { log.Debug("Keystore key decoding failed: ", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } // set/update the username and globalid values to those from the authentication body.Username = username body.Globalid = globalid // set the keys timestamp body.KeyData.TimeStamp = db.DateTime(time.Now()) if !body.Validate() { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } mgr := keystore.NewManager(r) // check if this user/organization already has a key under this label if _, err := mgr.GetKeyStoreKey(username, globalid, body.Label); err == nil { http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict) return } err := mgr.Create(&body) if err != nil { log.Error("error while saving keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } key, err := mgr.GetKeyStoreKey(username, globalid, body.Label) if err != nil { log.Error("error while retrieving keystore key: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } w.Header().Set("Content-type", "application/json") w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(key) }
[ "func", "(", "api", "UsersAPI", ")", "SaveKeyStoreKey", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "username", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"", "\"", "]", "\n", "globalid", ":=", "co...
// SaveKeyStoreKey returns all the publickeys written to the user by an organizaton
[ "SaveKeyStoreKey", "returns", "all", "the", "publickeys", "written", "to", "the", "user", "by", "an", "organizaton" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2534-L2582
14,025
itsyouonline/identityserver
identityservice/user/users_api.go
validateNewAvatar
func validateNewAvatar(w http.ResponseWriter, label string, u *user.User) bool { if !user.IsValidLabel(label) { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return false } if isReservedAvatarLabel(label) { writeErrorResponse(w, http.StatusConflict, "reserved_label") return false } if _, err := u.GetAvatarByLabel(label); err == nil { writeErrorResponse(w, http.StatusConflict, "duplicate_label") return false } // count the amount of avatars we already have if !(getUserAvatarCount(u) < maxAvatarAmount) { log.Debug("User has reached the max amount of avatars to upload") writeErrorResponse(w, http.StatusConflict, "max_avatar_amount") return false } return true }
go
func validateNewAvatar(w http.ResponseWriter, label string, u *user.User) bool { if !user.IsValidLabel(label) { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return false } if isReservedAvatarLabel(label) { writeErrorResponse(w, http.StatusConflict, "reserved_label") return false } if _, err := u.GetAvatarByLabel(label); err == nil { writeErrorResponse(w, http.StatusConflict, "duplicate_label") return false } // count the amount of avatars we already have if !(getUserAvatarCount(u) < maxAvatarAmount) { log.Debug("User has reached the max amount of avatars to upload") writeErrorResponse(w, http.StatusConflict, "max_avatar_amount") return false } return true }
[ "func", "validateNewAvatar", "(", "w", "http", ".", "ResponseWriter", ",", "label", "string", ",", "u", "*", "user", ".", "User", ")", "bool", "{", "if", "!", "user", ".", "IsValidLabel", "(", "label", ")", "{", "http", ".", "Error", "(", "w", ",", ...
// validateNewAvatar validates the label of a new avatar and whether the user can // still add avatars. Returns false if validation fails and an error has been written
[ "validateNewAvatar", "validates", "the", "label", "of", "a", "new", "avatar", "and", "whether", "the", "user", "can", "still", "add", "avatars", ".", "Returns", "false", "if", "validation", "fails", "and", "an", "error", "has", "been", "written" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2973-L2996
14,026
itsyouonline/identityserver
identityservice/user/users_api.go
isReservedAvatarLabel
func isReservedAvatarLabel(label string) bool { for _, plabel := range reservedAvatarLabels { if strings.ToLower(label) == plabel { return true } } return false }
go
func isReservedAvatarLabel(label string) bool { for _, plabel := range reservedAvatarLabels { if strings.ToLower(label) == plabel { return true } } return false }
[ "func", "isReservedAvatarLabel", "(", "label", "string", ")", "bool", "{", "for", "_", ",", "plabel", ":=", "range", "reservedAvatarLabels", "{", "if", "strings", ".", "ToLower", "(", "label", ")", "==", "plabel", "{", "return", "true", "\n", "}", "\n", ...
// isReservedAvatarLabel checks if this is a reserved label
[ "isReservedAvatarLabel", "checks", "if", "this", "is", "a", "reserved", "label" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L2999-L3006
14,027
itsyouonline/identityserver
identityservice/user/users_api.go
validateAvatarUpdateLabels
func validateAvatarUpdateLabels(oldLabel string, newLabel string, username string, userMgr *user.Manager, w http.ResponseWriter) (*user.Avatar, bool) { // lets not change reserved labels. if isReservedAvatarLabel(oldLabel) { log.Debug("trying to modify reserved label") writeErrorResponse(w, http.StatusConflict, "changing_protected_label") return nil, true } if isReservedAvatarLabel(newLabel) { log.Debug("trying to assign protected label") writeErrorResponse(w, http.StatusConflict, "assign_reserved_label") return nil, true } u, err := userMgr.GetByName(username) if handleServerError(w, "getting user from db", err) { return nil, true } // make sure the avatar we want to update exists oldAvatar, err := u.GetAvatarByLabel(oldLabel) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return nil, true } // check if we already have this label in case it gets renamed if oldLabel != newLabel { if _, err = u.GetAvatarByLabel(newLabel); err == nil { writeErrorResponse(w, http.StatusConflict, "duplicate_label") return nil, true } } return &oldAvatar, false }
go
func validateAvatarUpdateLabels(oldLabel string, newLabel string, username string, userMgr *user.Manager, w http.ResponseWriter) (*user.Avatar, bool) { // lets not change reserved labels. if isReservedAvatarLabel(oldLabel) { log.Debug("trying to modify reserved label") writeErrorResponse(w, http.StatusConflict, "changing_protected_label") return nil, true } if isReservedAvatarLabel(newLabel) { log.Debug("trying to assign protected label") writeErrorResponse(w, http.StatusConflict, "assign_reserved_label") return nil, true } u, err := userMgr.GetByName(username) if handleServerError(w, "getting user from db", err) { return nil, true } // make sure the avatar we want to update exists oldAvatar, err := u.GetAvatarByLabel(oldLabel) if err != nil { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) return nil, true } // check if we already have this label in case it gets renamed if oldLabel != newLabel { if _, err = u.GetAvatarByLabel(newLabel); err == nil { writeErrorResponse(w, http.StatusConflict, "duplicate_label") return nil, true } } return &oldAvatar, false }
[ "func", "validateAvatarUpdateLabels", "(", "oldLabel", "string", ",", "newLabel", "string", ",", "username", "string", ",", "userMgr", "*", "user", ".", "Manager", ",", "w", "http", ".", "ResponseWriter", ")", "(", "*", "user", ".", "Avatar", ",", "bool", ...
// validateAvatarUpdateLabels validates old and new avatar labels and returns a // pointer to the old avatar object. The secondary response value indicates whether // an error has occurred. In this case callers must not write to the ResponseWriter // again.
[ "validateAvatarUpdateLabels", "validates", "old", "and", "new", "avatar", "labels", "and", "returns", "a", "pointer", "to", "the", "old", "avatar", "object", ".", "The", "secondary", "response", "value", "indicates", "whether", "an", "error", "has", "occurred", ...
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L3247-L3283
14,028
itsyouonline/identityserver
identityservice/user/users_api.go
replaceAvatar
func replaceAvatar(w http.ResponseWriter, r *http.Request, oldAvatar *user.Avatar, newAvatar *user.Avatar, username string, userMgr *user.Manager) { var err error // If the old avatar points to a file on itsyou.online, we need to remove the file stored here. if strings.HasPrefix(strings.TrimPrefix(oldAvatar.Source, "https://"), r.Host) { hash := getAvatarHashFromLink(oldAvatar.Source) err = userMgr.RemoveAvatarFile(hash) if handleServerError(w, "removing avatar file", err) { return } } // now remove the old avatar err = userMgr.RemoveAvatar(username, oldAvatar.Label) if handleServerError(w, "removing old avatar", err) { return } // insert the new avatar err = userMgr.SaveAvatar(username, *newAvatar) if handleServerError(w, "saving new avatar", err) { return } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(newAvatar) }
go
func replaceAvatar(w http.ResponseWriter, r *http.Request, oldAvatar *user.Avatar, newAvatar *user.Avatar, username string, userMgr *user.Manager) { var err error // If the old avatar points to a file on itsyou.online, we need to remove the file stored here. if strings.HasPrefix(strings.TrimPrefix(oldAvatar.Source, "https://"), r.Host) { hash := getAvatarHashFromLink(oldAvatar.Source) err = userMgr.RemoveAvatarFile(hash) if handleServerError(w, "removing avatar file", err) { return } } // now remove the old avatar err = userMgr.RemoveAvatar(username, oldAvatar.Label) if handleServerError(w, "removing old avatar", err) { return } // insert the new avatar err = userMgr.SaveAvatar(username, *newAvatar) if handleServerError(w, "saving new avatar", err) { return } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(newAvatar) }
[ "func", "replaceAvatar", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "oldAvatar", "*", "user", ".", "Avatar", ",", "newAvatar", "*", "user", ".", "Avatar", ",", "username", "string", ",", "userMgr", "*", "user", ...
// replaceAvatar replaces an old avatar with a new one. It also removes avatar // files stored on the server if the link is updated or a new file is uploaded
[ "replaceAvatar", "replaces", "an", "old", "avatar", "with", "a", "new", "one", ".", "It", "also", "removes", "avatar", "files", "stored", "on", "the", "server", "if", "the", "link", "is", "updated", "or", "a", "new", "file", "is", "uploaded" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L3287-L3313
14,029
itsyouonline/identityserver
identityservice/user/users_api.go
getUserAvatarCount
func getUserAvatarCount(u *user.User) int { avatarCount := 0 countAvatars: for _, avatar := range u.Avatars { for _, reservedLabel := range reservedAvatarLabels { if avatar.Label == reservedLabel { continue countAvatars } } avatarCount++ } return avatarCount }
go
func getUserAvatarCount(u *user.User) int { avatarCount := 0 countAvatars: for _, avatar := range u.Avatars { for _, reservedLabel := range reservedAvatarLabels { if avatar.Label == reservedLabel { continue countAvatars } } avatarCount++ } return avatarCount }
[ "func", "getUserAvatarCount", "(", "u", "*", "user", ".", "User", ")", "int", "{", "avatarCount", ":=", "0", "\n", "countAvatars", ":", "for", "_", ",", "avatar", ":=", "range", "u", ".", "Avatars", "{", "for", "_", ",", "reservedLabel", ":=", "range",...
// getUserAvatarCount gets the user avatar count
[ "getUserAvatarCount", "gets", "the", "user", "avatar", "count" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/identityservice/user/users_api.go#L3401-L3413
14,030
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
LookupIyoID
func (s *UsersService) LookupIyoID(identifier string, headers, queryParams map[string]interface{}) (IyoID, *http.Response, error) { var err error var respBody200 IyoID resp, err := s.client.doReqNoBody("GET", s.client.BaseURI+"/users/identifiers/"+identifier, headers, queryParams) if err != nil { return respBody200, nil, err } defer resp.Body.Close() switch resp.StatusCode { case 200: err = json.NewDecoder(resp.Body).Decode(&respBody200) default: err = goraml.NewAPIError(resp, nil) } return respBody200, resp, err }
go
func (s *UsersService) LookupIyoID(identifier string, headers, queryParams map[string]interface{}) (IyoID, *http.Response, error) { var err error var respBody200 IyoID resp, err := s.client.doReqNoBody("GET", s.client.BaseURI+"/users/identifiers/"+identifier, headers, queryParams) if err != nil { return respBody200, nil, err } defer resp.Body.Close() switch resp.StatusCode { case 200: err = json.NewDecoder(resp.Body).Decode(&respBody200) default: err = goraml.NewAPIError(resp, nil) } return respBody200, resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "LookupIyoID", "(", "identifier", "string", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "IyoID", ",", "*", "http", ".", "Response", ",", "error", ")", "{", ...
// Lookup the username for an iyo id
[ "Lookup", "the", "username", "for", "an", "iyo", "id" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L26-L44
14,031
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
UpdateAuthorization
func (s *UsersService) UpdateAuthorization(grantedTo, username string, body Authorization, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/users/"+username+"/authorizations/"+grantedTo, &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
go
func (s *UsersService) UpdateAuthorization(grantedTo, username string, body Authorization, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/users/"+username+"/authorizations/"+grantedTo, &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "UpdateAuthorization", "(", "grantedTo", ",", "username", "string", ",", "body", "Authorization", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "http", ".", ...
// Modify which information an organization is able to see.
[ "Modify", "which", "information", "an", "organization", "is", "able", "to", "see", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L259-L269
14,032
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
LeaveOrganization
func (s *UsersService) LeaveOrganization(globalid, username string, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/users/"+username+"/organizations/"+globalid+"/leave", headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() switch resp.StatusCode { case 404: var respBody404 Error err = goraml.NewAPIError(resp, &respBody404) default: err = goraml.NewAPIError(resp, nil) } return resp, err }
go
func (s *UsersService) LeaveOrganization(globalid, username string, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/users/"+username+"/organizations/"+globalid+"/leave", headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() switch resp.StatusCode { case 404: var respBody404 Error err = goraml.NewAPIError(resp, &respBody404) default: err = goraml.NewAPIError(resp, nil) } return resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "LeaveOrganization", "(", "globalid", ",", "username", "string", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "http", ".", "Response", ",", "error", ")", ...
// Removes the user from an organization
[ "Removes", "the", "user", "from", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L918-L936
14,033
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
RejectMembership
func (s *UsersService) RejectMembership(globalid, role, username string, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/users/"+username+"/organizations/"+globalid+"/roles/"+role, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
go
func (s *UsersService) RejectMembership(globalid, role, username string, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqNoBody("DELETE", s.client.BaseURI+"/users/"+username+"/organizations/"+globalid+"/roles/"+role, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "RejectMembership", "(", "globalid", ",", "role", ",", "username", "string", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "http", ".", "Response", ",", ...
// Reject membership invitation in an organization.
[ "Reject", "membership", "invitation", "in", "an", "organization", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L939-L949
14,034
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
UpdatePassword
func (s *UsersService) UpdatePassword(username string, body UsersUsernamePasswordPutReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/users/"+username+"/password", &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() switch resp.StatusCode { case 422: var respBody422 Error err = goraml.NewAPIError(resp, &respBody422) default: err = goraml.NewAPIError(resp, nil) } return resp, err }
go
func (s *UsersService) UpdatePassword(username string, body UsersUsernamePasswordPutReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/users/"+username+"/password", &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() switch resp.StatusCode { case 422: var respBody422 Error err = goraml.NewAPIError(resp, &respBody422) default: err = goraml.NewAPIError(resp, nil) } return resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "UpdatePassword", "(", "username", "string", ",", "body", "UsersUsernamePasswordPutReqBody", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "http", ".", "Respon...
// Update the user his password
[ "Update", "the", "user", "his", "password" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L994-L1012
14,035
itsyouonline/identityserver
clients/go/itsyouonline/users_service.go
SetupTOTP
func (s *UsersService) SetupTOTP(username string, body TOTPSecret, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("POST", s.client.BaseURI+"/users/"+username+"/totp", &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
go
func (s *UsersService) SetupTOTP(username string, body TOTPSecret, headers, queryParams map[string]interface{}) (*http.Response, error) { var err error resp, err := s.client.doReqWithBody("POST", s.client.BaseURI+"/users/"+username+"/totp", &body, headers, queryParams) if err != nil { return nil, err } defer resp.Body.Close() return resp, err }
[ "func", "(", "s", "*", "UsersService", ")", "SetupTOTP", "(", "username", "string", ",", "body", "TOTPSecret", ",", "headers", ",", "queryParams", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "*", "http", ".", "Response", ",", "error", "...
// Enable two-factor authentication using TOTP.
[ "Enable", "two", "-", "factor", "authentication", "using", "TOTP", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/clients/go/itsyouonline/users_service.go#L1458-L1468
14,036
itsyouonline/identityserver
db/company/db.go
Get
func (cm *CompanyManager) Get(id string) (*Company, error) { var company Company objectId := bson.ObjectIdHex(id) if err := cm.collection.FindId(objectId).One(&company); err != nil { return nil, err } return &company, nil }
go
func (cm *CompanyManager) Get(id string) (*Company, error) { var company Company objectId := bson.ObjectIdHex(id) if err := cm.collection.FindId(objectId).One(&company); err != nil { return nil, err } return &company, nil }
[ "func", "(", "cm", "*", "CompanyManager", ")", "Get", "(", "id", "string", ")", "(", "*", "Company", ",", "error", ")", "{", "var", "company", "Company", "\n\n", "objectId", ":=", "bson", ".", "ObjectIdHex", "(", "id", ")", "\n\n", "if", "err", ":=",...
// Get company by ID.
[ "Get", "company", "by", "ID", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/company/db.go#L46-L56
14,037
itsyouonline/identityserver
db/company/db.go
GetByName
func (cm *CompanyManager) GetByName(globalId string) (*Company, error) { var company Company err := cm.collection.Find(bson.M{"globalid": globalId}).One(&company) return &company, err }
go
func (cm *CompanyManager) GetByName(globalId string) (*Company, error) { var company Company err := cm.collection.Find(bson.M{"globalid": globalId}).One(&company) return &company, err }
[ "func", "(", "cm", "*", "CompanyManager", ")", "GetByName", "(", "globalId", "string", ")", "(", "*", "Company", ",", "error", ")", "{", "var", "company", "Company", "\n\n", "err", ":=", "cm", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{...
//GetByName get a company by globalid.
[ "GetByName", "get", "a", "company", "by", "globalid", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/company/db.go#L59-L65
14,038
itsyouonline/identityserver
db/company/db.go
Exists
func (cm *CompanyManager) Exists(globalId string) bool { count, _ := cm.collection.Find(bson.M{"globalid": globalId}).Count() return count != 1 }
go
func (cm *CompanyManager) Exists(globalId string) bool { count, _ := cm.collection.Find(bson.M{"globalid": globalId}).Count() return count != 1 }
[ "func", "(", "cm", "*", "CompanyManager", ")", "Exists", "(", "globalId", "string", ")", "bool", "{", "count", ",", "_", ":=", "cm", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globalId", "}", ")", ".", "Count", ...
//Exists checks if a company exists.
[ "Exists", "checks", "if", "a", "company", "exists", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/company/db.go#L68-L72
14,039
itsyouonline/identityserver
db/company/db.go
Create
func (cm *CompanyManager) Create(company *Company) error { // TODO: Validation! company.ID = bson.NewObjectId() err := cm.collection.Insert(company) if mgo.IsDup(err) { return db.ErrDuplicate } return err }
go
func (cm *CompanyManager) Create(company *Company) error { // TODO: Validation! company.ID = bson.NewObjectId() err := cm.collection.Insert(company) if mgo.IsDup(err) { return db.ErrDuplicate } return err }
[ "func", "(", "cm", "*", "CompanyManager", ")", "Create", "(", "company", "*", "Company", ")", "error", "{", "// TODO: Validation!", "company", ".", "ID", "=", "bson", ".", "NewObjectId", "(", ")", "\n", "err", ":=", "cm", ".", "collection", ".", "Insert"...
// Create a company.
[ "Create", "a", "company", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/company/db.go#L79-L88
14,040
itsyouonline/identityserver
db/organization/db.go
getLogoCollection
func getLogoCollection(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, logoCollectionName) }
go
func getLogoCollection(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, logoCollectionName) }
[ "func", "getLogoCollection", "(", "session", "*", "mgo", ".", "Session", ")", "*", "mgo", ".", "Collection", "{", "return", "db", ".", "GetCollection", "(", "session", ",", "logoCollectionName", ")", "\n", "}" ]
//get the logo collection
[ "get", "the", "logo", "collection" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L119-L121
14,041
itsyouonline/identityserver
db/organization/db.go
getLast2FACollection
func getLast2FACollection(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, last2FACollectionName) }
go
func getLast2FACollection(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, last2FACollectionName) }
[ "func", "getLast2FACollection", "(", "session", "*", "mgo", ".", "Session", ")", "*", "mgo", ".", "Collection", "{", "return", "db", ".", "GetCollection", "(", "session", ",", "last2FACollectionName", ")", "\n", "}" ]
//get the last 2FA collection
[ "get", "the", "last", "2FA", "collection" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L124-L126
14,042
itsyouonline/identityserver
db/organization/db.go
getDescriptionManager
func getDescriptionManager(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, descriptionCollectionName) }
go
func getDescriptionManager(session *mgo.Session) *mgo.Collection { return db.GetCollection(session, descriptionCollectionName) }
[ "func", "getDescriptionManager", "(", "session", "*", "mgo", ".", "Session", ")", "*", "mgo", ".", "Collection", "{", "return", "db", ".", "GetCollection", "(", "session", ",", "descriptionCollectionName", ")", "\n", "}" ]
//get the info text collection
[ "get", "the", "info", "text", "collection" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L129-L131
14,043
itsyouonline/identityserver
db/organization/db.go
NewLogoManager
func NewLogoManager(r *http.Request) *LogoManager { session := db.GetDBSession(r) return &LogoManager{ session: session, collection: getLogoCollection(session), } }
go
func NewLogoManager(r *http.Request) *LogoManager { session := db.GetDBSession(r) return &LogoManager{ session: session, collection: getLogoCollection(session), } }
[ "func", "NewLogoManager", "(", "r", "*", "http", ".", "Request", ")", "*", "LogoManager", "{", "session", ":=", "db", ".", "GetDBSession", "(", "r", ")", "\n", "return", "&", "LogoManager", "{", "session", ":", "session", ",", "collection", ":", "getLogo...
//NewLogoManager creates and initializes a new LogoManager
[ "NewLogoManager", "creates", "and", "initializes", "a", "new", "LogoManager" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L143-L149
14,044
itsyouonline/identityserver
db/organization/db.go
NewLast2FAManager
func NewLast2FAManager(r *http.Request) *Last2FAManager { session := db.GetDBSession(r) return &Last2FAManager{ session: session, collection: getLast2FACollection(session), } }
go
func NewLast2FAManager(r *http.Request) *Last2FAManager { session := db.GetDBSession(r) return &Last2FAManager{ session: session, collection: getLast2FACollection(session), } }
[ "func", "NewLast2FAManager", "(", "r", "*", "http", ".", "Request", ")", "*", "Last2FAManager", "{", "session", ":=", "db", ".", "GetDBSession", "(", "r", ")", "\n", "return", "&", "Last2FAManager", "{", "session", ":", "session", ",", "collection", ":", ...
// NewLast2FAManager creates and initializes a new Last2FAManager
[ "NewLast2FAManager", "creates", "and", "initializes", "a", "new", "Last2FAManager" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L152-L158
14,045
itsyouonline/identityserver
db/organization/db.go
NewDescriptionManager
func NewDescriptionManager(r *http.Request) *DescriptionManager { session := db.GetDBSession(r) return &DescriptionManager{ session: session, collection: getDescriptionManager(session), } }
go
func NewDescriptionManager(r *http.Request) *DescriptionManager { session := db.GetDBSession(r) return &DescriptionManager{ session: session, collection: getDescriptionManager(session), } }
[ "func", "NewDescriptionManager", "(", "r", "*", "http", ".", "Request", ")", "*", "DescriptionManager", "{", "session", ":=", "db", ".", "GetDBSession", "(", "r", ")", "\n", "return", "&", "DescriptionManager", "{", "session", ":", "session", ",", "collectio...
// NewDescriptionManager creates and initializes a new DescriptionManager
[ "NewDescriptionManager", "creates", "and", "initializes", "a", "new", "DescriptionManager" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L161-L167
14,046
itsyouonline/identityserver
db/organization/db.go
GetOrganizations
func (m *Manager) GetOrganizations(organizationIDs []string) ([]Organization, error) { var organizations []Organization err := m.collection.Find(bson.M{"globalid": bson.M{"$in": organizationIDs}}).All(&organizations) return organizations, err }
go
func (m *Manager) GetOrganizations(organizationIDs []string) ([]Organization, error) { var organizations []Organization err := m.collection.Find(bson.M{"globalid": bson.M{"$in": organizationIDs}}).All(&organizations) return organizations, err }
[ "func", "(", "m", "*", "Manager", ")", "GetOrganizations", "(", "organizationIDs", "[", "]", "string", ")", "(", "[", "]", "Organization", ",", "error", ")", "{", "var", "organizations", "[", "]", "Organization", "\n\n", "err", ":=", "m", ".", "collectio...
// GetOrganizations gets a list of organizations.
[ "GetOrganizations", "gets", "a", "list", "of", "organizations", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L170-L176
14,047
itsyouonline/identityserver
db/organization/db.go
GetSubOrganizationsMultiple
func (m *Manager) GetSubOrganizationsMultiple(globalIDs []string) ([]Organization, error) { var organizations = make([]Organization, 0, 0) regexes := []interface{}{} for _, globalID := range globalIDs { regexes = append(regexes, bson.RegEx{"^" + globalID + `\.`, ""}) } var qry = bson.M{"globalid": bson.M{"$in": regexes}} if err := m.collection.Find(qry).All(&organizations); err != nil { return nil, err } return organizations, nil }
go
func (m *Manager) GetSubOrganizationsMultiple(globalIDs []string) ([]Organization, error) { var organizations = make([]Organization, 0, 0) regexes := []interface{}{} for _, globalID := range globalIDs { regexes = append(regexes, bson.RegEx{"^" + globalID + `\.`, ""}) } var qry = bson.M{"globalid": bson.M{"$in": regexes}} if err := m.collection.Find(qry).All(&organizations); err != nil { return nil, err } return organizations, nil }
[ "func", "(", "m", "*", "Manager", ")", "GetSubOrganizationsMultiple", "(", "globalIDs", "[", "]", "string", ")", "(", "[", "]", "Organization", ",", "error", ")", "{", "var", "organizations", "=", "make", "(", "[", "]", "Organization", ",", "0", ",", "...
// GetSubOrganizationsMultiple loads all suborganizations of the input organizations
[ "GetSubOrganizationsMultiple", "loads", "all", "suborganizations", "of", "the", "input", "organizations" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L191-L208
14,048
itsyouonline/identityserver
db/organization/db.go
isDirectOwner
func (m *Manager) isDirectOwner(globalID, username string) (isowner bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "owners": username}).Count() isowner = (matches > 0) return }
go
func (m *Manager) isDirectOwner(globalID, username string) (isowner bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "owners": username}).Count() isowner = (matches > 0) return }
[ "func", "(", "m", "*", "Manager", ")", "isDirectOwner", "(", "globalID", ",", "username", "string", ")", "(", "isowner", "bool", ",", "err", "error", ")", "{", "matches", ",", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M", ...
//isDirectOwner checks if a specific user is in the owners list of an organization
[ "isDirectOwner", "checks", "if", "a", "specific", "user", "is", "in", "the", "owners", "list", "of", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L211-L215
14,049
itsyouonline/identityserver
db/organization/db.go
isDirectOwnerOfOrgs
func (m *Manager) isDirectOwnerOfOrgs(globalIDs []string, username string) (ownedOrgs []string, err error) { var orgs []Organization err = m.collection.Find(bson.M{"globalid": bson.M{"$in": globalIDs}, "owners": username}).Select(bson.M{"globalid": 1}).All(&orgs) ownedOrgs = make([]string, len(orgs)) for i, org := range orgs { ownedOrgs[i] = org.Globalid } return }
go
func (m *Manager) isDirectOwnerOfOrgs(globalIDs []string, username string) (ownedOrgs []string, err error) { var orgs []Organization err = m.collection.Find(bson.M{"globalid": bson.M{"$in": globalIDs}, "owners": username}).Select(bson.M{"globalid": 1}).All(&orgs) ownedOrgs = make([]string, len(orgs)) for i, org := range orgs { ownedOrgs[i] = org.Globalid } return }
[ "func", "(", "m", "*", "Manager", ")", "isDirectOwnerOfOrgs", "(", "globalIDs", "[", "]", "string", ",", "username", "string", ")", "(", "ownedOrgs", "[", "]", "string", ",", "err", "error", ")", "{", "var", "orgs", "[", "]", "Organization", "\n", "err...
// isDirectOwnerOfOrgs takes a list of organizations and a username, and returns a list of organizations where // this username is in the list of "owners"
[ "isDirectOwnerOfOrgs", "takes", "a", "list", "of", "organizations", "and", "a", "username", "and", "returns", "a", "list", "of", "organizations", "where", "this", "username", "is", "in", "the", "list", "of", "owners" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L219-L227
14,050
itsyouonline/identityserver
db/organization/db.go
IsInOrgs
func (m *Manager) IsInOrgs(username string, globalIDs ...string) ([]string, error) { var wg sync.WaitGroup passed := make([]bool, len(globalIDs)) errors := make([]error, len(globalIDs)) for i, globalID := range globalIDs { wg.Add(1) go func(index int, gID string) { defer wg.Done() passed[index], errors[index] = m.isOwnerOrMember(gID, username, make(map[string]bool)) }(i, globalID) } // Wait untill we are done wg.Wait() // Report if there was any error for _, err := range errors { if err != nil { return nil, err } } var result []string for i, p := range passed { if p { result = append(result, globalIDs[i]) } } return result, nil }
go
func (m *Manager) IsInOrgs(username string, globalIDs ...string) ([]string, error) { var wg sync.WaitGroup passed := make([]bool, len(globalIDs)) errors := make([]error, len(globalIDs)) for i, globalID := range globalIDs { wg.Add(1) go func(index int, gID string) { defer wg.Done() passed[index], errors[index] = m.isOwnerOrMember(gID, username, make(map[string]bool)) }(i, globalID) } // Wait untill we are done wg.Wait() // Report if there was any error for _, err := range errors { if err != nil { return nil, err } } var result []string for i, p := range passed { if p { result = append(result, globalIDs[i]) } } return result, nil }
[ "func", "(", "m", "*", "Manager", ")", "IsInOrgs", "(", "username", "string", ",", "globalIDs", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "wg", "sync", ".", "WaitGroup", "\n", "passed", ":=", "make", "(", "[", "]...
// IsInOrgs checks if a user is somehow in the provided orgs // returns a list of all the orgs where the user is an owner or member
[ "IsInOrgs", "checks", "if", "a", "user", "is", "somehow", "in", "the", "provided", "orgs", "returns", "a", "list", "of", "all", "the", "orgs", "where", "the", "user", "is", "an", "owner", "or", "member" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L231-L257
14,051
itsyouonline/identityserver
db/organization/db.go
SplitOwnedOrgs
func (m *Manager) SplitOwnedOrgs(globalIDs []string, username string) (ownedOrgs []string, memberOrgs []string, err error) { // Backward loops here are so we can slice out the element in the globalIDs list without // affecting the remainder of the elements if len(globalIDs) == 0 { return []string{}, []string{}, nil } // Find all orgs where we are a direct owner ownedOrgs, err = m.isDirectOwnerOfOrgs(globalIDs, username) if err != nil { return } // Remove all orgs we already know to be owned by this user for _, ownedOrg := range ownedOrgs { for i := len(globalIDs) - 1; i >= 0; i-- { if ownedOrg == globalIDs[i] { globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) break } } } // Now check all parent orgs // TODO: sort and optimize this loop by manually iterating parentOrgs := []string{} for _, globalID := range globalIDs { parents := findParentOrgs(globalID) for _, parent := range parents { alreadyKnown := false for _, knownParent := range parentOrgs { if parent == knownParent { alreadyKnown = true break } } if !alreadyKnown { parentOrgs = append(parentOrgs, parent) } } } ownedParentOrgs, parentOrgs, err := m.SplitOwnedOrgs(parentOrgs, username) if err != nil { return } for _, ownedParent := range ownedParentOrgs { for i := len(globalIDs) - 1; i >= 0; i-- { if strings.HasPrefix(globalIDs[i], ownedParent+".") { ownedOrgs = append(ownedOrgs, globalIDs[i]) globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) } } } // If not a direct or inherited owner, iterate through the list of owning organizations // TODO: this can be fixed with a map imo, so we can keep the amount of db calls to a minimum for i := len(globalIDs) - 1; i >= 0; i-- { var owned bool owned, err = m.orgIsOwned(globalIDs[i], username) if err != nil { return } if owned { ownedOrgs = append(ownedOrgs, globalIDs[i]) globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) } } memberOrgs = globalIDs return }
go
func (m *Manager) SplitOwnedOrgs(globalIDs []string, username string) (ownedOrgs []string, memberOrgs []string, err error) { // Backward loops here are so we can slice out the element in the globalIDs list without // affecting the remainder of the elements if len(globalIDs) == 0 { return []string{}, []string{}, nil } // Find all orgs where we are a direct owner ownedOrgs, err = m.isDirectOwnerOfOrgs(globalIDs, username) if err != nil { return } // Remove all orgs we already know to be owned by this user for _, ownedOrg := range ownedOrgs { for i := len(globalIDs) - 1; i >= 0; i-- { if ownedOrg == globalIDs[i] { globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) break } } } // Now check all parent orgs // TODO: sort and optimize this loop by manually iterating parentOrgs := []string{} for _, globalID := range globalIDs { parents := findParentOrgs(globalID) for _, parent := range parents { alreadyKnown := false for _, knownParent := range parentOrgs { if parent == knownParent { alreadyKnown = true break } } if !alreadyKnown { parentOrgs = append(parentOrgs, parent) } } } ownedParentOrgs, parentOrgs, err := m.SplitOwnedOrgs(parentOrgs, username) if err != nil { return } for _, ownedParent := range ownedParentOrgs { for i := len(globalIDs) - 1; i >= 0; i-- { if strings.HasPrefix(globalIDs[i], ownedParent+".") { ownedOrgs = append(ownedOrgs, globalIDs[i]) globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) } } } // If not a direct or inherited owner, iterate through the list of owning organizations // TODO: this can be fixed with a map imo, so we can keep the amount of db calls to a minimum for i := len(globalIDs) - 1; i >= 0; i-- { var owned bool owned, err = m.orgIsOwned(globalIDs[i], username) if err != nil { return } if owned { ownedOrgs = append(ownedOrgs, globalIDs[i]) globalIDs = append(globalIDs[:i], globalIDs[i+1:]...) } } memberOrgs = globalIDs return }
[ "func", "(", "m", "*", "Manager", ")", "SplitOwnedOrgs", "(", "globalIDs", "[", "]", "string", ",", "username", "string", ")", "(", "ownedOrgs", "[", "]", "string", ",", "memberOrgs", "[", "]", "string", ",", "err", "error", ")", "{", "// Backward loops ...
// SplitOwnedOrgs removes the organizations of which the user is an owner from the input lists and moves them // into a separate list which is returned
[ "SplitOwnedOrgs", "removes", "the", "organizations", "of", "which", "the", "user", "is", "an", "owner", "from", "the", "input", "lists", "and", "moves", "them", "into", "a", "separate", "list", "which", "is", "returned" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L376-L449
14,052
itsyouonline/identityserver
db/organization/db.go
OrganizationIsOwner
func (m *Manager) OrganizationIsOwner(globalID, organization string) (isowner bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "orgowners": organization}).Count() isowner = (matches > 0) return }
go
func (m *Manager) OrganizationIsOwner(globalID, organization string) (isowner bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "orgowners": organization}).Count() isowner = (matches > 0) return }
[ "func", "(", "m", "*", "Manager", ")", "OrganizationIsOwner", "(", "globalID", ",", "organization", "string", ")", "(", "isowner", "bool", ",", "err", "error", ")", "{", "matches", ",", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", "."...
//OrganizationIsOwner checks if organization2 is an owner of organization1
[ "OrganizationIsOwner", "checks", "if", "organization2", "is", "an", "owner", "of", "organization1" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L497-L501
14,053
itsyouonline/identityserver
db/organization/db.go
isDirectMember
func (m *Manager) isDirectMember(globalID, username string) (ismember bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "members": username}).Count() ismember = (matches > 0) return }
go
func (m *Manager) isDirectMember(globalID, username string) (ismember bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "members": username}).Count() ismember = (matches > 0) return }
[ "func", "(", "m", "*", "Manager", ")", "isDirectMember", "(", "globalID", ",", "username", "string", ")", "(", "ismember", "bool", ",", "err", "error", ")", "{", "matches", ",", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M",...
//isDirectMember checks if a specific user is in the members list of an organization
[ "isDirectMember", "checks", "if", "a", "specific", "user", "is", "in", "the", "members", "list", "of", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L504-L508
14,054
itsyouonline/identityserver
db/organization/db.go
IsMember
func (m *Manager) IsMember(globalID, username string) (result bool, err error) { if !m.Exists(globalID) { return } result, err = m.isDirectMember(globalID, username) if result || err != nil { return } // If not a direct member, check the membership in the parent organization lastSubOrgSeperator := strings.LastIndex(globalID, ".") if lastSubOrgSeperator > 0 { result, err = m.IsMember(globalID[:lastSubOrgSeperator], username) if result || err != nil { return } } // If not a direct or inherited member, iterate through the list of member organizations var org Organization err = m.collection.Find(bson.M{"globalid": globalID}).Select(bson.M{"orgmembers": 1, "includesuborgsof": 1}).One(&org) if err != nil { if mgo.ErrNotFound == err { err = nil } return } excludelist := make(map[string]bool) excludelist[globalID] = true // Also get the suborganizations if they have been added var includesuborgs []string for _, member := range org.OrgMembers { for _, include := range org.IncludeSubOrgsOf { if member == include { includesuborgs = append(includesuborgs, include) } } } var subOrgs []Organization for _, subOrg := range includesuborgs { subOrganizations, err := m.GetSubOrganizations(subOrg) if err != nil && err != mgo.ErrNotFound { return false, err } subOrgs = append(subOrgs, subOrganizations...) } var orgs []string for _, suborganization := range subOrgs { orgs = append(orgs, suborganization.Globalid) } for _, owningOrganization := range append(org.OrgMembers, orgs...) { result, err = m.isOwnerOrMember(owningOrganization, username, excludelist) if result || err != nil { return } } return }
go
func (m *Manager) IsMember(globalID, username string) (result bool, err error) { if !m.Exists(globalID) { return } result, err = m.isDirectMember(globalID, username) if result || err != nil { return } // If not a direct member, check the membership in the parent organization lastSubOrgSeperator := strings.LastIndex(globalID, ".") if lastSubOrgSeperator > 0 { result, err = m.IsMember(globalID[:lastSubOrgSeperator], username) if result || err != nil { return } } // If not a direct or inherited member, iterate through the list of member organizations var org Organization err = m.collection.Find(bson.M{"globalid": globalID}).Select(bson.M{"orgmembers": 1, "includesuborgsof": 1}).One(&org) if err != nil { if mgo.ErrNotFound == err { err = nil } return } excludelist := make(map[string]bool) excludelist[globalID] = true // Also get the suborganizations if they have been added var includesuborgs []string for _, member := range org.OrgMembers { for _, include := range org.IncludeSubOrgsOf { if member == include { includesuborgs = append(includesuborgs, include) } } } var subOrgs []Organization for _, subOrg := range includesuborgs { subOrganizations, err := m.GetSubOrganizations(subOrg) if err != nil && err != mgo.ErrNotFound { return false, err } subOrgs = append(subOrgs, subOrganizations...) } var orgs []string for _, suborganization := range subOrgs { orgs = append(orgs, suborganization.Globalid) } for _, owningOrganization := range append(org.OrgMembers, orgs...) { result, err = m.isOwnerOrMember(owningOrganization, username, excludelist) if result || err != nil { return } } return }
[ "func", "(", "m", "*", "Manager", ")", "IsMember", "(", "globalID", ",", "username", "string", ")", "(", "result", "bool", ",", "err", "error", ")", "{", "if", "!", "m", ".", "Exists", "(", "globalID", ")", "{", "return", "\n", "}", "\n", "result",...
//IsMember checks if a specific user is in the members list of an organization // or belongs to an organization that is in the member list // it also checks this for the parentorganization
[ "IsMember", "checks", "if", "a", "specific", "user", "is", "in", "the", "members", "list", "of", "an", "organization", "or", "belongs", "to", "an", "organization", "that", "is", "in", "the", "member", "list", "it", "also", "checks", "this", "for", "the", ...
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L513-L570
14,055
itsyouonline/identityserver
db/organization/db.go
OrganizationIsMember
func (m *Manager) OrganizationIsMember(globalID, organization string) (ismember bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "orgmembers": organization}).Count() ismember = (matches > 0) return }
go
func (m *Manager) OrganizationIsMember(globalID, organization string) (ismember bool, err error) { matches, err := m.collection.Find(bson.M{"globalid": globalID, "orgmembers": organization}).Count() ismember = (matches > 0) return }
[ "func", "(", "m", "*", "Manager", ")", "OrganizationIsMember", "(", "globalID", ",", "organization", "string", ")", "(", "ismember", "bool", ",", "err", "error", ")", "{", "matches", ",", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", "...
//OrganizationIsMember checks if organization2 is a member of organization1
[ "OrganizationIsMember", "checks", "if", "organization2", "is", "a", "member", "of", "organization1" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L573-L577
14,056
itsyouonline/identityserver
db/organization/db.go
OrganizationIsPartOf
func (m *Manager) OrganizationIsPartOf(globalID, organization string) (bool, error) { condition := []interface{}{ bson.M{"orgmembers": organization}, bson.M{"orgowners": organization}, } qry := []interface{}{ bson.M{"globalid": globalID}, bson.M{"$or": condition}, } occurrences, err := m.collection.Find(bson.M{"$and": qry}).Count() return occurrences == 1, err }
go
func (m *Manager) OrganizationIsPartOf(globalID, organization string) (bool, error) { condition := []interface{}{ bson.M{"orgmembers": organization}, bson.M{"orgowners": organization}, } qry := []interface{}{ bson.M{"globalid": globalID}, bson.M{"$or": condition}, } occurrences, err := m.collection.Find(bson.M{"$and": qry}).Count() return occurrences == 1, err }
[ "func", "(", "m", "*", "Manager", ")", "OrganizationIsPartOf", "(", "globalID", ",", "organization", "string", ")", "(", "bool", ",", "error", ")", "{", "condition", ":=", "[", "]", "interface", "{", "}", "{", "bson", ".", "M", "{", "\"", "\"", ":", ...
//OrganizationIsPartOf checks if organization2 is a member or an owner of organization1
[ "OrganizationIsPartOf", "checks", "if", "organization2", "is", "a", "member", "or", "an", "owner", "of", "organization1" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L580-L591
14,057
itsyouonline/identityserver
db/organization/db.go
AllByUser
func (m *Manager) AllByUser(username string) ([]Organization, error) { var organizations []Organization //TODO: handle this a bit smarter, select only the ones where the user is owner first, and take select only the org name //do the same for the orgs where the username is member but not owners //No need to pull in 1000's of records for this condition := []interface{}{ bson.M{"members": username}, bson.M{"owners": username}, } err := m.collection.Find(bson.M{"$or": condition}).All(&organizations) return organizations, err }
go
func (m *Manager) AllByUser(username string) ([]Organization, error) { var organizations []Organization //TODO: handle this a bit smarter, select only the ones where the user is owner first, and take select only the org name //do the same for the orgs where the username is member but not owners //No need to pull in 1000's of records for this condition := []interface{}{ bson.M{"members": username}, bson.M{"owners": username}, } err := m.collection.Find(bson.M{"$or": condition}).All(&organizations) return organizations, err }
[ "func", "(", "m", "*", "Manager", ")", "AllByUser", "(", "username", "string", ")", "(", "[", "]", "Organization", ",", "error", ")", "{", "var", "organizations", "[", "]", "Organization", "\n", "//TODO: handle this a bit smarter, select only the ones where the user...
// AllByUser get organizations for certain user.
[ "AllByUser", "get", "organizations", "for", "certain", "user", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L594-L608
14,058
itsyouonline/identityserver
db/organization/db.go
AllByOrgs
func (m *Manager) AllByOrgs(globalIDs []string) ([]Organization, error) { var organizations []Organization condition := []interface{}{ bson.M{"orgmembers": bson.M{"$in": globalIDs}}, bson.M{"orgowners": bson.M{"$in": globalIDs}}, } err := m.collection.Find(bson.M{"$or": condition}).All(&organizations) return organizations, err }
go
func (m *Manager) AllByOrgs(globalIDs []string) ([]Organization, error) { var organizations []Organization condition := []interface{}{ bson.M{"orgmembers": bson.M{"$in": globalIDs}}, bson.M{"orgowners": bson.M{"$in": globalIDs}}, } err := m.collection.Find(bson.M{"$or": condition}).All(&organizations) return organizations, err }
[ "func", "(", "m", "*", "Manager", ")", "AllByOrgs", "(", "globalIDs", "[", "]", "string", ")", "(", "[", "]", "Organization", ",", "error", ")", "{", "var", "organizations", "[", "]", "Organization", "\n\n", "condition", ":=", "[", "]", "interface", "{...
// AllByOrgs get organizations where at least one organization of those provided is an owner or member
[ "AllByOrgs", "get", "organizations", "where", "at", "least", "one", "organization", "of", "those", "provided", "is", "an", "owner", "or", "member" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L800-L811
14,059
itsyouonline/identityserver
db/organization/db.go
Get
func (m *Manager) Get(id string) (*Organization, error) { var organization Organization objectID := bson.ObjectIdHex(id) if err := m.collection.FindId(objectID).One(&organization); err != nil { return nil, err } return &organization, nil }
go
func (m *Manager) Get(id string) (*Organization, error) { var organization Organization objectID := bson.ObjectIdHex(id) if err := m.collection.FindId(objectID).One(&organization); err != nil { return nil, err } return &organization, nil }
[ "func", "(", "m", "*", "Manager", ")", "Get", "(", "id", "string", ")", "(", "*", "Organization", ",", "error", ")", "{", "var", "organization", "Organization", "\n\n", "objectID", ":=", "bson", ".", "ObjectIdHex", "(", "id", ")", "\n\n", "if", "err", ...
// Get organization by ID.
[ "Get", "organization", "by", "ID", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L814-L824
14,060
itsyouonline/identityserver
db/organization/db.go
GetByName
func (m *Manager) GetByName(globalID string) (organization *Organization, err error) { err = m.collection.Find(bson.M{"globalid": globalID}).One(&organization) // Check if organization isnt a nullpointer in case no org was found with this globalID if organization != nil && organization.RequiredScopes == nil { organization.RequiredScopes = []RequiredScope{} } return }
go
func (m *Manager) GetByName(globalID string) (organization *Organization, err error) { err = m.collection.Find(bson.M{"globalid": globalID}).One(&organization) // Check if organization isnt a nullpointer in case no org was found with this globalID if organization != nil && organization.RequiredScopes == nil { organization.RequiredScopes = []RequiredScope{} } return }
[ "func", "(", "m", "*", "Manager", ")", "GetByName", "(", "globalID", "string", ")", "(", "organization", "*", "Organization", ",", "err", "error", ")", "{", "err", "=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{", "\"", "\"", ":...
// GetByName gets an organization by Name.
[ "GetByName", "gets", "an", "organization", "by", "Name", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L827-L834
14,061
itsyouonline/identityserver
db/organization/db.go
Exists
func (m *Manager) Exists(globalID string) bool { count, _ := m.collection.Find(bson.M{"globalid": globalID}).Count() return count == 1 }
go
func (m *Manager) Exists(globalID string) bool { count, _ := m.collection.Find(bson.M{"globalid": globalID}).Count() return count == 1 }
[ "func", "(", "m", "*", "Manager", ")", "Exists", "(", "globalID", "string", ")", "bool", "{", "count", ",", "_", ":=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", ")", ".", "Count", "(", ")...
// Exists checks if an organization exists.
[ "Exists", "checks", "if", "an", "organization", "exists", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L842-L846
14,062
itsyouonline/identityserver
db/organization/db.go
Exists
func (m *Last2FAManager) Exists(globalID string, username string) bool { condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } count, _ := m.collection.Find(bson.M{"$and": condition}).Count() return count == 1 }
go
func (m *Last2FAManager) Exists(globalID string, username string) bool { condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } count, _ := m.collection.Find(bson.M{"$and": condition}).Count() return count == 1 }
[ "func", "(", "m", "*", "Last2FAManager", ")", "Exists", "(", "globalID", "string", ",", "username", "string", ")", "bool", "{", "condition", ":=", "[", "]", "interface", "{", "}", "{", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", ",", "...
// Exists checks if an organization - user combination entry exists.
[ "Exists", "checks", "if", "an", "organization", "-", "user", "combination", "entry", "exists", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L856-L864
14,063
itsyouonline/identityserver
db/organization/db.go
Create
func (m *LogoManager) Create(organization *Organization) error { var orgLogo OrganizationLogo orgLogo.Globalid = organization.Globalid err := m.collection.Insert(orgLogo) if mgo.IsDup(err) { return db.ErrDuplicate } return err }
go
func (m *LogoManager) Create(organization *Organization) error { var orgLogo OrganizationLogo orgLogo.Globalid = organization.Globalid err := m.collection.Insert(orgLogo) if mgo.IsDup(err) { return db.ErrDuplicate } return err }
[ "func", "(", "m", "*", "LogoManager", ")", "Create", "(", "organization", "*", "Organization", ")", "error", "{", "var", "orgLogo", "OrganizationLogo", "\n\n", "orgLogo", ".", "Globalid", "=", "organization", ".", "Globalid", "\n\n", "err", ":=", "m", ".", ...
// Create a new organization entry in the organization logo collection
[ "Create", "a", "new", "organization", "entry", "in", "the", "organization", "logo", "collection" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L878-L888
14,064
itsyouonline/identityserver
db/organization/db.go
SaveMember
func (m *Manager) SaveMember(organization *Organization, username string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"members": username}}) }
go
func (m *Manager) SaveMember(organization *Organization, username string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"members": username}}) }
[ "func", "(", "m", "*", "Manager", ")", "SaveMember", "(", "organization", "*", "Organization", ",", "username", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "organization", "...
// SaveMember save or update member
[ "SaveMember", "save", "or", "update", "member" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L891-L895
14,065
itsyouonline/identityserver
db/organization/db.go
SaveOwner
func (m *Manager) SaveOwner(organization *Organization, owner string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"owners": owner}}) }
go
func (m *Manager) SaveOwner(organization *Organization, owner string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"owners": owner}}) }
[ "func", "(", "m", "*", "Manager", ")", "SaveOwner", "(", "organization", "*", "Organization", ",", "owner", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "organization", ".", ...
// SaveOwner save or update owners
[ "SaveOwner", "save", "or", "update", "owners" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L905-L909
14,066
itsyouonline/identityserver
db/organization/db.go
SaveOrgMember
func (m *Manager) SaveOrgMember(organization *Organization, organizationID string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"orgmembers": organizationID}}) }
go
func (m *Manager) SaveOrgMember(organization *Organization, organizationID string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$addToSet": bson.M{"orgmembers": organizationID}}) }
[ "func", "(", "m", "*", "Manager", ")", "SaveOrgMember", "(", "organization", "*", "Organization", ",", "organizationID", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "organizat...
// SaveOrgMember save or update organization member
[ "SaveOrgMember", "save", "or", "update", "organization", "member" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L919-L923
14,067
itsyouonline/identityserver
db/organization/db.go
RemoveDNS
func (m *Manager) RemoveDNS(organization *Organization, dns string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$pull": bson.M{"dns": dns}}) }
go
func (m *Manager) RemoveDNS(organization *Organization, dns string) error { return m.collection.Update( bson.M{"globalid": organization.Globalid}, bson.M{"$pull": bson.M{"dns": dns}}) }
[ "func", "(", "m", "*", "Manager", ")", "RemoveDNS", "(", "organization", "*", "Organization", ",", "dns", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "organization", ".", ...
// RemoveDNS remove DNS
[ "RemoveDNS", "remove", "DNS" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L979-L983
14,068
itsyouonline/identityserver
db/organization/db.go
RemoveByOrganization
func (m *Last2FAManager) RemoveByOrganization(globalid string) error { _, err := m.collection.RemoveAll(bson.M{"globalid": globalid}) return err }
go
func (m *Last2FAManager) RemoveByOrganization(globalid string) error { _, err := m.collection.RemoveAll(bson.M{"globalid": globalid}) return err }
[ "func", "(", "m", "*", "Last2FAManager", ")", "RemoveByOrganization", "(", "globalid", "string", ")", "error", "{", "_", ",", "err", ":=", "m", ".", "collection", ".", "RemoveAll", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globalid", "}", ")", "\...
// Remove the Last2FA entries for this organization
[ "Remove", "the", "Last2FA", "entries", "for", "this", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L996-L999
14,069
itsyouonline/identityserver
db/organization/db.go
RemoveByUser
func (m *Last2FAManager) RemoveByUser(username string) error { _, err := m.collection.RemoveAll(bson.M{"username": username}) return err }
go
func (m *Last2FAManager) RemoveByUser(username string) error { _, err := m.collection.RemoveAll(bson.M{"username": username}) return err }
[ "func", "(", "m", "*", "Last2FAManager", ")", "RemoveByUser", "(", "username", "string", ")", "error", "{", "_", ",", "err", ":=", "m", ".", "collection", ".", "RemoveAll", "(", "bson", ".", "M", "{", "\"", "\"", ":", "username", "}", ")", "\n", "r...
//Remove the Last2FA entries for this user
[ "Remove", "the", "Last2FA", "entries", "for", "this", "user" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1002-L1005
14,070
itsyouonline/identityserver
db/organization/db.go
Remove
func (m *DescriptionManager) Remove(globalid string) error { return m.collection.Remove(bson.M{"globalid": globalid}) }
go
func (m *DescriptionManager) Remove(globalid string) error { return m.collection.Remove(bson.M{"globalid": globalid}) }
[ "func", "(", "m", "*", "DescriptionManager", ")", "Remove", "(", "globalid", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Remove", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globalid", "}", ")", "\n", "}" ]
// Remove removes the organization descriptions
[ "Remove", "removes", "the", "organization", "descriptions" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1008-L1010
14,071
itsyouonline/identityserver
db/organization/db.go
UpdateMembership
func (m *Manager) UpdateMembership(globalid string, username string, oldrole string, newrole string) error { qry := bson.M{"globalid": globalid} pull := bson.M{ "$pull": bson.M{oldrole: username}, } push := bson.M{ "$addToSet": bson.M{newrole: username}, } err := m.collection.Update(qry, pull) if err != nil { return err } return m.collection.Update(qry, push) }
go
func (m *Manager) UpdateMembership(globalid string, username string, oldrole string, newrole string) error { qry := bson.M{"globalid": globalid} pull := bson.M{ "$pull": bson.M{oldrole: username}, } push := bson.M{ "$addToSet": bson.M{newrole: username}, } err := m.collection.Update(qry, pull) if err != nil { return err } return m.collection.Update(qry, push) }
[ "func", "(", "m", "*", "Manager", ")", "UpdateMembership", "(", "globalid", "string", ",", "username", "string", ",", "oldrole", "string", ",", "newrole", "string", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalid", "}"...
// UpdateMembership Updates a user his role in an organization
[ "UpdateMembership", "Updates", "a", "user", "his", "role", "in", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1013-L1026
14,072
itsyouonline/identityserver
db/organization/db.go
CountByUser
func (m *Manager) CountByUser(username string) (int, error) { qry := bson.M{"owners": username} return m.collection.Find(qry).Count() }
go
func (m *Manager) CountByUser(username string) (int, error) { qry := bson.M{"owners": username} return m.collection.Find(qry).Count() }
[ "func", "(", "m", "*", "Manager", ")", "CountByUser", "(", "username", "string", ")", "(", "int", ",", "error", ")", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "username", "}", "\n", "return", "m", ".", "collection", ".", "Find", "...
// CountByUser counts the amount of organizations by user
[ "CountByUser", "counts", "the", "amount", "of", "organizations", "by", "user" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1045-L1048
14,073
itsyouonline/identityserver
db/organization/db.go
CountByOrganization
func (m *Manager) CountByOrganization(organization string) (int, error) { qry := bson.M{"orgowners": organization} return m.collection.Find(qry).Count() }
go
func (m *Manager) CountByOrganization(organization string) (int, error) { qry := bson.M{"orgowners": organization} return m.collection.Find(qry).Count() }
[ "func", "(", "m", "*", "Manager", ")", "CountByOrganization", "(", "organization", "string", ")", "(", "int", ",", "error", ")", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "organization", "}", "\n", "return", "m", ".", "collection", "....
// CountByOrganization counts the amount of organizations where the organization is an owner
[ "CountByOrganization", "counts", "the", "amount", "of", "organizations", "where", "the", "organization", "is", "an", "owner" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1051-L1054
14,074
itsyouonline/identityserver
db/organization/db.go
RemoveUser
func (m *Manager) RemoveUser(globalID string, username string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$pull": bson.M{"owners": username, "members": username}} return m.collection.Update(qry, update) }
go
func (m *Manager) RemoveUser(globalID string, username string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$pull": bson.M{"owners": username, "members": username}} return m.collection.Update(qry, update) }
[ "func", "(", "m", "*", "Manager", ")", "RemoveUser", "(", "globalID", "string", ",", "username", "string", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", "\n", "update", ":=", "bson", ".", "M", "{", "\"", ...
// RemoveUser Removes a user from an organization
[ "RemoveUser", "Removes", "a", "user", "from", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1057-L1061
14,075
itsyouonline/identityserver
db/organization/db.go
RemoveOrganization
func (m *Manager) RemoveOrganization(globalID string, organization string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$pull": bson.M{"orgowners": organization, "orgmembers": organization}} return m.collection.Update(qry, update) }
go
func (m *Manager) RemoveOrganization(globalID string, organization string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$pull": bson.M{"orgowners": organization, "orgmembers": organization}} return m.collection.Update(qry, update) }
[ "func", "(", "m", "*", "Manager", ")", "RemoveOrganization", "(", "globalID", "string", ",", "organization", "string", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", "\n", "update", ":=", "bson", ".", "M", "{...
// RemoveOrganization Removes an organization as member or owner from another organization
[ "RemoveOrganization", "Removes", "an", "organization", "as", "member", "or", "owner", "from", "another", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1064-L1068
14,076
itsyouonline/identityserver
db/organization/db.go
GetValidity
func (m *Manager) GetValidity(globalID string) (int, error) { var org Organization err := m.collection.Find(bson.M{"globalid": globalID}).One(&org) if err != nil { return 0, err } seconds := org.SecondsValidity if seconds == -1 { //special value to avoid confusion with mongo null return 0, err } else if seconds == 0 { //mongo null for int field, use default duration return 3600 * 24 * 7, err //7 days default duration } else { return seconds, err } }
go
func (m *Manager) GetValidity(globalID string) (int, error) { var org Organization err := m.collection.Find(bson.M{"globalid": globalID}).One(&org) if err != nil { return 0, err } seconds := org.SecondsValidity if seconds == -1 { //special value to avoid confusion with mongo null return 0, err } else if seconds == 0 { //mongo null for int field, use default duration return 3600 * 24 * 7, err //7 days default duration } else { return seconds, err } }
[ "func", "(", "m", "*", "Manager", ")", "GetValidity", "(", "globalID", "string", ")", "(", "int", ",", "error", ")", "{", "var", "org", "Organization", "\n", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{", "\"", "\"", ...
// GetValidity gets the 2FA validity duration in seconds
[ "GetValidity", "gets", "the", "2FA", "validity", "duration", "in", "seconds" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1071-L1085
14,077
itsyouonline/identityserver
db/organization/db.go
SaveLogo
func (m *LogoManager) SaveLogo(globalID string, logo string) (*mgo.ChangeInfo, error) { return m.collection.Upsert( bson.M{"globalid": globalID}, bson.M{"$set": bson.M{"logo": logo}}) }
go
func (m *LogoManager) SaveLogo(globalID string, logo string) (*mgo.ChangeInfo, error) { return m.collection.Upsert( bson.M{"globalid": globalID}, bson.M{"$set": bson.M{"logo": logo}}) }
[ "func", "(", "m", "*", "LogoManager", ")", "SaveLogo", "(", "globalID", "string", ",", "logo", "string", ")", "(", "*", "mgo", ".", "ChangeInfo", ",", "error", ")", "{", "return", "m", ".", "collection", ".", "Upsert", "(", "bson", ".", "M", "{", "...
// SaveLogo save or update logo
[ "SaveLogo", "save", "or", "update", "logo" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1097-L1101
14,078
itsyouonline/identityserver
db/organization/db.go
GetLogo
func (m *LogoManager) GetLogo(globalID string) (string, error) { var org *OrganizationLogo err := m.collection.Find(bson.M{"globalid": globalID}).One(&org) if err != nil { return "", err } return org.Logo, err }
go
func (m *LogoManager) GetLogo(globalID string) (string, error) { var org *OrganizationLogo err := m.collection.Find(bson.M{"globalid": globalID}).One(&org) if err != nil { return "", err } return org.Logo, err }
[ "func", "(", "m", "*", "LogoManager", ")", "GetLogo", "(", "globalID", "string", ")", "(", "string", ",", "error", ")", "{", "var", "org", "*", "OrganizationLogo", "\n", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson", ".", "M", "{", ...
// GetLogo Gets the logo from an organization
[ "GetLogo", "Gets", "the", "logo", "from", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1104-L1111
14,079
itsyouonline/identityserver
db/organization/db.go
RemoveLogo
func (m *LogoManager) RemoveLogo(globalID string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$unset": bson.M{"logo": 1}} return m.collection.Update(qry, update) }
go
func (m *LogoManager) RemoveLogo(globalID string) error { qry := bson.M{"globalid": globalID} update := bson.M{"$unset": bson.M{"logo": 1}} return m.collection.Update(qry, update) }
[ "func", "(", "m", "*", "LogoManager", ")", "RemoveLogo", "(", "globalID", "string", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", "\n", "update", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "bson", "."...
// RemoveLogo Removes the logo from an organization
[ "RemoveLogo", "Removes", "the", "logo", "from", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1114-L1118
14,080
itsyouonline/identityserver
db/organization/db.go
SetLast2FA
func (m *Last2FAManager) SetLast2FA(globalID string, username string) error { now := time.Now() condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } _, err := m.collection.Upsert( bson.M{"$and": condition}, bson.M{"$set": bson.M{"last2fa": now}}) return err }
go
func (m *Last2FAManager) SetLast2FA(globalID string, username string) error { now := time.Now() condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } _, err := m.collection.Upsert( bson.M{"$and": condition}, bson.M{"$set": bson.M{"last2fa": now}}) return err }
[ "func", "(", "m", "*", "Last2FAManager", ")", "SetLast2FA", "(", "globalID", "string", ",", "username", "string", ")", "error", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "condition", ":=", "[", "]", "interface", "{", "}", "{", "bson", "."...
// SetLast2FA Set the last successful 2FA time
[ "SetLast2FA", "Set", "the", "last", "successful", "2FA", "time" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1121-L1131
14,081
itsyouonline/identityserver
db/organization/db.go
GetLast2FA
func (m *Last2FAManager) GetLast2FA(globalID string, username string) (db.DateTime, error) { var l2fa *UserLast2FALogin condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } err := m.collection.Find(bson.M{"$and": condition}).One(&l2fa) return l2fa.Last2FA, err }
go
func (m *Last2FAManager) GetLast2FA(globalID string, username string) (db.DateTime, error) { var l2fa *UserLast2FALogin condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } err := m.collection.Find(bson.M{"$and": condition}).One(&l2fa) return l2fa.Last2FA, err }
[ "func", "(", "m", "*", "Last2FAManager", ")", "GetLast2FA", "(", "globalID", "string", ",", "username", "string", ")", "(", "db", ".", "DateTime", ",", "error", ")", "{", "var", "l2fa", "*", "UserLast2FALogin", "\n", "condition", ":=", "[", "]", "interfa...
// GetLast2FA Gets the date of the last successful 2FA login, if no failed login attempts have occurred since then
[ "GetLast2FA", "Gets", "the", "date", "of", "the", "last", "successful", "2FA", "login", "if", "no", "failed", "login", "attempts", "have", "occurred", "since", "then" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1134-L1142
14,082
itsyouonline/identityserver
db/organization/db.go
RemoveLast2FA
func (m *Last2FAManager) RemoveLast2FA(globalID string, username string) error { condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } return m.collection.Remove(bson.M{"$and": condition}) }
go
func (m *Last2FAManager) RemoveLast2FA(globalID string, username string) error { condition := []interface{}{ bson.M{"globalid": globalID}, bson.M{"username": username}, } return m.collection.Remove(bson.M{"$and": condition}) }
[ "func", "(", "m", "*", "Last2FAManager", ")", "RemoveLast2FA", "(", "globalID", "string", ",", "username", "string", ")", "error", "{", "condition", ":=", "[", "]", "interface", "{", "}", "{", "bson", ".", "M", "{", "\"", "\"", ":", "globalID", "}", ...
// RemoveLast2FA Removes the entry of the last successful 2FA login for this organization - user combination
[ "RemoveLast2FA", "Removes", "the", "entry", "of", "the", "last", "successful", "2FA", "login", "for", "this", "organization", "-", "user", "combination" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1145-L1151
14,083
itsyouonline/identityserver
db/organization/db.go
AddRequiredScope
func (m *Manager) AddRequiredScope(globalId string, requiredScope RequiredScope) error { qry := bson.M{"globalid": globalId} update := bson.M{"$push": bson.M{"requiredscopes": requiredScope}} return m.collection.Update(qry, update) }
go
func (m *Manager) AddRequiredScope(globalId string, requiredScope RequiredScope) error { qry := bson.M{"globalid": globalId} update := bson.M{"$push": bson.M{"requiredscopes": requiredScope}} return m.collection.Update(qry, update) }
[ "func", "(", "m", "*", "Manager", ")", "AddRequiredScope", "(", "globalId", "string", ",", "requiredScope", "RequiredScope", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalId", "}", "\n", "update", ":=", "bson", ".", "M"...
// AddRequiredScope adds a required scope
[ "AddRequiredScope", "adds", "a", "required", "scope" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1154-L1158
14,084
itsyouonline/identityserver
db/organization/db.go
UpdateRequiredScope
func (m *Manager) UpdateRequiredScope(globalId string, oldRequiredScope string, newRequiredScope RequiredScope) error { qry := bson.M{ "globalid": globalId, "requiredscopes.scope": oldRequiredScope, } update := bson.M{ "$set": bson.M{ "requiredscopes.$": newRequiredScope, }, } return m.collection.Update(qry, update) }
go
func (m *Manager) UpdateRequiredScope(globalId string, oldRequiredScope string, newRequiredScope RequiredScope) error { qry := bson.M{ "globalid": globalId, "requiredscopes.scope": oldRequiredScope, } update := bson.M{ "$set": bson.M{ "requiredscopes.$": newRequiredScope, }, } return m.collection.Update(qry, update) }
[ "func", "(", "m", "*", "Manager", ")", "UpdateRequiredScope", "(", "globalId", "string", ",", "oldRequiredScope", "string", ",", "newRequiredScope", "RequiredScope", ")", "error", "{", "qry", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "globalId", ",", "...
// UpdateRequiredScope updates a required scope
[ "UpdateRequiredScope", "updates", "a", "required", "scope" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1161-L1172
14,085
itsyouonline/identityserver
db/organization/db.go
DeleteRequiredScope
func (m *Manager) DeleteRequiredScope(globalId string, requiredScope string) error { return m.collection.Update(bson.M{"globalid": globalId}, bson.M{"$pull": bson.M{"requiredscopes": bson.M{"scope": requiredScope}}}) }
go
func (m *Manager) DeleteRequiredScope(globalId string, requiredScope string) error { return m.collection.Update(bson.M{"globalid": globalId}, bson.M{"$pull": bson.M{"requiredscopes": bson.M{"scope": requiredScope}}}) }
[ "func", "(", "m", "*", "Manager", ")", "DeleteRequiredScope", "(", "globalId", "string", ",", "requiredScope", "string", ")", "error", "{", "return", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globalId", "}", "...
// DeleteRequiredScope deletes a required scope
[ "DeleteRequiredScope", "deletes", "a", "required", "scope" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1175-L1178
14,086
itsyouonline/identityserver
db/organization/db.go
SaveDescription
func (m *DescriptionManager) SaveDescription(globalId string, text LocalizedInfoText) error { _, err := m.collection.Upsert(bson.M{"globalid": globalId}, bson.M{"$addToSet": bson.M{"infotexts": text}}) return err }
go
func (m *DescriptionManager) SaveDescription(globalId string, text LocalizedInfoText) error { _, err := m.collection.Upsert(bson.M{"globalid": globalId}, bson.M{"$addToSet": bson.M{"infotexts": text}}) return err }
[ "func", "(", "m", "*", "DescriptionManager", ")", "SaveDescription", "(", "globalId", "string", ",", "text", "LocalizedInfoText", ")", "error", "{", "_", ",", "err", ":=", "m", ".", "collection", ".", "Upsert", "(", "bson", ".", "M", "{", "\"", "\"", "...
// SaveDescription saves a description for an organization
[ "SaveDescription", "saves", "a", "description", "for", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1196-L1199
14,087
itsyouonline/identityserver
db/organization/db.go
UpdateDescription
func (m *DescriptionManager) UpdateDescription(globalId string, text LocalizedInfoText) error { err := m.collection.Update(bson.M{"globalid": globalId}, bson.M{"$pull": bson.M{"infotexts": bson.M{"langkey": text.LangKey}}}) if err != nil { return err } _, err = m.collection.Upsert(bson.M{"globalid": globalId}, bson.M{"$addToSet": bson.M{"infotexts": text}}) return err }
go
func (m *DescriptionManager) UpdateDescription(globalId string, text LocalizedInfoText) error { err := m.collection.Update(bson.M{"globalid": globalId}, bson.M{"$pull": bson.M{"infotexts": bson.M{"langkey": text.LangKey}}}) if err != nil { return err } _, err = m.collection.Upsert(bson.M{"globalid": globalId}, bson.M{"$addToSet": bson.M{"infotexts": text}}) return err }
[ "func", "(", "m", "*", "DescriptionManager", ")", "UpdateDescription", "(", "globalId", "string", ",", "text", "LocalizedInfoText", ")", "error", "{", "err", ":=", "m", ".", "collection", ".", "Update", "(", "bson", ".", "M", "{", "\"", "\"", ":", "globa...
// UpdateDescription updates a description for an organization
[ "UpdateDescription", "updates", "a", "description", "for", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1202-L1209
14,088
itsyouonline/identityserver
db/organization/db.go
GetDescription
func (m *DescriptionManager) GetDescription(globalId string) (OrganizationInfoText, error) { var info OrganizationInfoText err := m.collection.Find(bson.M{"globalid": globalId}).One(&info) return info, err }
go
func (m *DescriptionManager) GetDescription(globalId string) (OrganizationInfoText, error) { var info OrganizationInfoText err := m.collection.Find(bson.M{"globalid": globalId}).One(&info) return info, err }
[ "func", "(", "m", "*", "DescriptionManager", ")", "GetDescription", "(", "globalId", "string", ")", "(", "OrganizationInfoText", ",", "error", ")", "{", "var", "info", "OrganizationInfoText", "\n", "err", ":=", "m", ".", "collection", ".", "Find", "(", "bson...
// GetDescription get all descriptions for an organization
[ "GetDescription", "get", "all", "descriptions", "for", "an", "organization" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/organization/db.go#L1217-L1221
14,089
itsyouonline/identityserver
siteservice/login.go
initLoginModels
func (service *Service) initLoginModels() { index := mgo.Index{ Key: []string{"sessionkey"}, Unique: true, DropDups: false, } db.EnsureIndex(mongoLoginCollectionName, index) automaticExpiration := mgo.Index{ Key: []string{"createdat"}, ExpireAfter: time.Second * 60 * 10, Background: true, } db.EnsureIndex(mongoLoginCollectionName, automaticExpiration) }
go
func (service *Service) initLoginModels() { index := mgo.Index{ Key: []string{"sessionkey"}, Unique: true, DropDups: false, } db.EnsureIndex(mongoLoginCollectionName, index) automaticExpiration := mgo.Index{ Key: []string{"createdat"}, ExpireAfter: time.Second * 60 * 10, Background: true, } db.EnsureIndex(mongoLoginCollectionName, automaticExpiration) }
[ "func", "(", "service", "*", "Service", ")", "initLoginModels", "(", ")", "{", "index", ":=", "mgo", ".", "Index", "{", "Key", ":", "[", "]", "string", "{", "\"", "\"", "}", ",", "Unique", ":", "true", ",", "DropDups", ":", "false", ",", "}", "\n...
//initLoginModels initialize models in mongo
[ "initLoginModels", "initialize", "models", "in", "mongo" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L40-L56
14,090
itsyouonline/identityserver
siteservice/login.go
ShowLoginForm
func (service *Service) ShowLoginForm(w http.ResponseWriter, request *http.Request) { htmlData, err := html.Asset(loginFileName) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } loginSession.Values["auth_client_id"] = request.URL.Query().Get("client_id") sessions.Save(request, w) w.Write(htmlData) }
go
func (service *Service) ShowLoginForm(w http.ResponseWriter, request *http.Request) { htmlData, err := html.Asset(loginFileName) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } loginSession.Values["auth_client_id"] = request.URL.Query().Get("client_id") sessions.Save(request, w) w.Write(htmlData) }
[ "func", "(", "service", "*", "Service", ")", "ShowLoginForm", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "htmlData", ",", "err", ":=", "html", ".", "Asset", "(", "loginFileName", ")", "\n", "if", "er...
//ShowLoginForm shows the user login page on the initial request
[ "ShowLoginForm", "shows", "the", "user", "login", "page", "on", "the", "initial", "request" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L82-L99
14,091
itsyouonline/identityserver
siteservice/login.go
GetTwoFactorAuthenticationMethods
func (service *Service) GetTwoFactorAuthenticationMethods(w http.ResponseWriter, request *http.Request) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } username, ok := loginSession.Values["username"].(string) if username == "" || !ok { http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } userMgr := user.NewManager(request) userFromDB, err := userMgr.GetByName(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } response := struct { Totp bool `json:"totp"` Sms map[string]string `json:"sms"` }{Sms: make(map[string]string)} totpMgr := totp.NewManager(request) response.Totp, err = totpMgr.HasTOTP(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } valMgr := validationdb.NewManager(request) verifiedPhones, err := valMgr.GetByUsernameValidatedPhonenumbers(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } for _, validatedPhoneNumber := range verifiedPhones { for _, number := range userFromDB.Phonenumbers { if number.Phonenumber == string(validatedPhoneNumber.Phonenumber) { response.Sms[number.Label] = string(validatedPhoneNumber.Phonenumber) } } } json.NewEncoder(w).Encode(response) return }
go
func (service *Service) GetTwoFactorAuthenticationMethods(w http.ResponseWriter, request *http.Request) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } username, ok := loginSession.Values["username"].(string) if username == "" || !ok { http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } userMgr := user.NewManager(request) userFromDB, err := userMgr.GetByName(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } response := struct { Totp bool `json:"totp"` Sms map[string]string `json:"sms"` }{Sms: make(map[string]string)} totpMgr := totp.NewManager(request) response.Totp, err = totpMgr.HasTOTP(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } valMgr := validationdb.NewManager(request) verifiedPhones, err := valMgr.GetByUsernameValidatedPhonenumbers(username) if err != nil { log.Error(err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } for _, validatedPhoneNumber := range verifiedPhones { for _, number := range userFromDB.Phonenumbers { if number.Phonenumber == string(validatedPhoneNumber.Phonenumber) { response.Sms[number.Label] = string(validatedPhoneNumber.Phonenumber) } } } json.NewEncoder(w).Encode(response) return }
[ "func", "(", "service", "*", "Service", ")", "GetTwoFactorAuthenticationMethods", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "loginSession", ",", "err", ":=", "service", ".", "GetSession", "(", "request", ...
// GetTwoFactorAuthenticationMethods returns the possible two factor authentication methods the user can use to login with.
[ "GetTwoFactorAuthenticationMethods", "returns", "the", "possible", "two", "factor", "authentication", "methods", "the", "user", "can", "use", "to", "login", "with", "." ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L256-L303
14,092
itsyouonline/identityserver
siteservice/login.go
getUserLoggingIn
func (service *Service) getUserLoggingIn(request *http.Request) (username string, err error) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) return } savedusername := loginSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
go
func (service *Service) getUserLoggingIn(request *http.Request) (username string, err error) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) return } savedusername := loginSession.Values["username"] if savedusername != nil { username, _ = savedusername.(string) } return }
[ "func", "(", "service", "*", "Service", ")", "getUserLoggingIn", "(", "request", "*", "http", ".", "Request", ")", "(", "username", "string", ",", "err", "error", ")", "{", "loginSession", ",", "err", ":=", "service", ".", "GetSession", "(", "request", "...
//getUserLoggingIn returns an user trying to log in, or an empty string if there is none
[ "getUserLoggingIn", "returns", "an", "user", "trying", "to", "log", "in", "or", "an", "empty", "string", "if", "there", "is", "none" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L306-L317
14,093
itsyouonline/identityserver
siteservice/login.go
getSessionKey
func (service *Service) getSessionKey(request *http.Request) (sessionKey string, err error) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) return } savedSessionKey := loginSession.Values["sessionkey"] if savedSessionKey != nil { sessionKey, _ = savedSessionKey.(string) } return }
go
func (service *Service) getSessionKey(request *http.Request) (sessionKey string, err error) { loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error(err) return } savedSessionKey := loginSession.Values["sessionkey"] if savedSessionKey != nil { sessionKey, _ = savedSessionKey.(string) } return }
[ "func", "(", "service", "*", "Service", ")", "getSessionKey", "(", "request", "*", "http", ".", "Request", ")", "(", "sessionKey", "string", ",", "err", "error", ")", "{", "loginSession", ",", "err", ":=", "service", ".", "GetSession", "(", "request", ",...
//getSessionKey returns an the login session key, or an empty string if there is none
[ "getSessionKey", "returns", "an", "the", "login", "session", "key", "or", "an", "empty", "string", "if", "there", "is", "none" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L320-L331
14,094
itsyouonline/identityserver
siteservice/login.go
ProcessTOTPConfirmation
func (service *Service) ProcessTOTPConfirmation(w http.ResponseWriter, request *http.Request) { username, err := service.getUserLoggingIn(request) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if username == "" { sessions.Save(request, w) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } values := struct { Totpcode string `json:"totpcode"` }{} if err := json.NewDecoder(request.Body).Decode(&values); err != nil { log.Debug("Error decoding the totp confirmation request:", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } var validtotpcode bool totpMgr := totp.NewManager(request) if validtotpcode, err = totpMgr.Validate(username, values.Totpcode); err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if !validtotpcode { //TODO: limit to 3 failed attempts w.WriteHeader(422) return } //add last 2fa date if logging in with oauth2 service.storeLast2FALogin(request, username) service.loginUser(w, request, username) }
go
func (service *Service) ProcessTOTPConfirmation(w http.ResponseWriter, request *http.Request) { username, err := service.getUserLoggingIn(request) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if username == "" { sessions.Save(request, w) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } values := struct { Totpcode string `json:"totpcode"` }{} if err := json.NewDecoder(request.Body).Decode(&values); err != nil { log.Debug("Error decoding the totp confirmation request:", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } var validtotpcode bool totpMgr := totp.NewManager(request) if validtotpcode, err = totpMgr.Validate(username, values.Totpcode); err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if !validtotpcode { //TODO: limit to 3 failed attempts w.WriteHeader(422) return } //add last 2fa date if logging in with oauth2 service.storeLast2FALogin(request, username) service.loginUser(w, request, username) }
[ "func", "(", "service", "*", "Service", ")", "ProcessTOTPConfirmation", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "username", ",", "err", ":=", "service", ".", "getUserLoggingIn", "(", "request", ")", "...
//ProcessTOTPConfirmation checks the totp 2 factor authentication code
[ "ProcessTOTPConfirmation", "checks", "the", "totp", "2", "factor", "authentication", "code" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L427-L462
14,095
itsyouonline/identityserver
siteservice/login.go
PhonenumberValidationAndLogin
func (service *Service) PhonenumberValidationAndLogin(w http.ResponseWriter, request *http.Request) { err := request.ParseForm() if err != nil { log.Debug(err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } values := request.Form key := values.Get("k") smscode := values.Get("c") langKey := values.Get("l") translationValues := tools.TranslationValues{ "invalidlink": nil, "error": nil, "smsconfirmedandlogin": nil, "return_to_window": nil, } translations, err := tools.ParseTranslations(langKey, translationValues) if err != nil { log.Error("Failed to parse translations: ", err) return } err = service.phonenumberValidationService.ConfirmValidation(request, key, smscode) if err == validation.ErrInvalidCode || err == validation.ErrInvalidOrExpiredKey { service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } if err != nil { log.Error(err) service.renderSMSConfirmationPage(w, request, translations["error"], "") return } sessionInfo, err := service.getLoginSessionInformation(request, key) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if sessionInfo == nil { service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } validsmscode := (smscode == sessionInfo.SMSCode) if !validsmscode { //TODO: limit to 3 failed attempts service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } mgoCollection := db.GetCollection(db.GetDBSession(request), mongoLoginCollectionName) _, err = mgoCollection.UpdateAll(bson.M{"sessionkey": key}, bson.M{"$set": bson.M{"confirmed": true}}) if err != nil { log.Error("Error while confirming sms 2fa - ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } service.renderSMSConfirmationPage(w, request, translations["smsconfirmedandlogin"], translations["return_to_window"]) }
go
func (service *Service) PhonenumberValidationAndLogin(w http.ResponseWriter, request *http.Request) { err := request.ParseForm() if err != nil { log.Debug(err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } values := request.Form key := values.Get("k") smscode := values.Get("c") langKey := values.Get("l") translationValues := tools.TranslationValues{ "invalidlink": nil, "error": nil, "smsconfirmedandlogin": nil, "return_to_window": nil, } translations, err := tools.ParseTranslations(langKey, translationValues) if err != nil { log.Error("Failed to parse translations: ", err) return } err = service.phonenumberValidationService.ConfirmValidation(request, key, smscode) if err == validation.ErrInvalidCode || err == validation.ErrInvalidOrExpiredKey { service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } if err != nil { log.Error(err) service.renderSMSConfirmationPage(w, request, translations["error"], "") return } sessionInfo, err := service.getLoginSessionInformation(request, key) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if sessionInfo == nil { service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } validsmscode := (smscode == sessionInfo.SMSCode) if !validsmscode { //TODO: limit to 3 failed attempts service.renderSMSConfirmationPage(w, request, translations["invalidlink"], "") return } mgoCollection := db.GetCollection(db.GetDBSession(request), mongoLoginCollectionName) _, err = mgoCollection.UpdateAll(bson.M{"sessionkey": key}, bson.M{"$set": bson.M{"confirmed": true}}) if err != nil { log.Error("Error while confirming sms 2fa - ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } service.renderSMSConfirmationPage(w, request, translations["smsconfirmedandlogin"], translations["return_to_window"]) }
[ "func", "(", "service", "*", "Service", ")", "PhonenumberValidationAndLogin", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "err", ":=", "request", ".", "ParseForm", "(", ")", "\n", "if", "err", "!=", "ni...
// PhonenumberValidationAndLogin is the page that is linked to in the SMS for phonenumbervalidation // and login. Therefore it is accessed on the mobile phone
[ "PhonenumberValidationAndLogin", "is", "the", "page", "that", "is", "linked", "to", "in", "the", "SMS", "for", "phonenumbervalidation", "and", "login", ".", "Therefore", "it", "is", "accessed", "on", "the", "mobile", "phone" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L485-L550
14,096
itsyouonline/identityserver
siteservice/login.go
Check2FASMSConfirmation
func (service *Service) Check2FASMSConfirmation(w http.ResponseWriter, request *http.Request) { sessionInfo, err := service.getLoginSessionInformation(request, "") if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } response := map[string]bool{} if sessionInfo == nil { response["confirmed"] = false } else { response["confirmed"] = sessionInfo.Confirmed } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(response) }
go
func (service *Service) Check2FASMSConfirmation(w http.ResponseWriter, request *http.Request) { sessionInfo, err := service.getLoginSessionInformation(request, "") if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } response := map[string]bool{} if sessionInfo == nil { response["confirmed"] = false } else { response["confirmed"] = sessionInfo.Confirmed } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(response) }
[ "func", "(", "service", "*", "Service", ")", "Check2FASMSConfirmation", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "sessionInfo", ",", "err", ":=", "service", ".", "getLoginSessionInformation", "(", "request...
//Check2FASMSConfirmation is called by the sms code form to check if the sms is already confirmed on the mobile phone
[ "Check2FASMSConfirmation", "is", "called", "by", "the", "sms", "code", "form", "to", "check", "if", "the", "sms", "is", "already", "confirmed", "on", "the", "mobile", "phone" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L609-L625
14,097
itsyouonline/identityserver
siteservice/login.go
Process2FASMSConfirmation
func (service *Service) Process2FASMSConfirmation(w http.ResponseWriter, request *http.Request) { username, err := service.getUserLoggingIn(request) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if username == "" { sessions.Save(request, w) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } values := struct { Smscode string `json:"smscode"` }{} if err := json.NewDecoder(request.Body).Decode(&values); err != nil { log.Debug("Error decoding the totp confirmation request:", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } sessionInfo, err := service.getLoginSessionInformation(request, "") if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if sessionInfo != nil && !sessionInfo.Confirmed { //Already confirmed on the phone validsmscode := (values.Smscode == sessionInfo.SMSCode) if !validsmscode { // TODO: limit to 3 failed attempts w.WriteHeader(422) log.Debugf("Expected code %s, got %s", sessionInfo.SMSCode, values.Smscode) return } } loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error("Failed to get loginsession: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } validationkey, _ := loginSession.Values["phonenumbervalidationkey"].(string) err = service.phonenumberValidationService.ConfirmValidation(request, validationkey, values.Smscode) if err == validation.ErrInvalidCode { log.Debug("Invalid code") // TODO: limit to 3 failed attempts w.WriteHeader(422) log.Debug("invalid code") return } userMgr := user.NewManager(request) userMgr.RemoveExpireDate(username) //add last 2fa date if logging in with oauth2 service.storeLast2FALogin(request, username) service.loginUser(w, request, username) }
go
func (service *Service) Process2FASMSConfirmation(w http.ResponseWriter, request *http.Request) { username, err := service.getUserLoggingIn(request) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if username == "" { sessions.Save(request, w) http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } values := struct { Smscode string `json:"smscode"` }{} if err := json.NewDecoder(request.Body).Decode(&values); err != nil { log.Debug("Error decoding the totp confirmation request:", err) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } sessionInfo, err := service.getLoginSessionInformation(request, "") if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } if sessionInfo != nil && !sessionInfo.Confirmed { //Already confirmed on the phone validsmscode := (values.Smscode == sessionInfo.SMSCode) if !validsmscode { // TODO: limit to 3 failed attempts w.WriteHeader(422) log.Debugf("Expected code %s, got %s", sessionInfo.SMSCode, values.Smscode) return } } loginSession, err := service.GetSession(request, SessionLogin, "loginsession") if err != nil { log.Error("Failed to get loginsession: ", err) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } validationkey, _ := loginSession.Values["phonenumbervalidationkey"].(string) err = service.phonenumberValidationService.ConfirmValidation(request, validationkey, values.Smscode) if err == validation.ErrInvalidCode { log.Debug("Invalid code") // TODO: limit to 3 failed attempts w.WriteHeader(422) log.Debug("invalid code") return } userMgr := user.NewManager(request) userMgr.RemoveExpireDate(username) //add last 2fa date if logging in with oauth2 service.storeLast2FALogin(request, username) service.loginUser(w, request, username) }
[ "func", "(", "service", "*", "Service", ")", "Process2FASMSConfirmation", "(", "w", "http", ".", "ResponseWriter", ",", "request", "*", "http", ".", "Request", ")", "{", "username", ",", "err", ":=", "service", ".", "getUserLoggingIn", "(", "request", ")", ...
//Process2FASMSConfirmation checks the totp 2 factor authentication code
[ "Process2FASMSConfirmation", "checks", "the", "totp", "2", "factor", "authentication", "code" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/siteservice/login.go#L628-L687
14,098
itsyouonline/identityserver
communication/email.go
NewSMTPEmailService
func NewSMTPEmailService(host string, port int, user string, password string) (service *SMTPEmailService) { dialer := gomail.NewDialer(host, port, user, password) service = &SMTPEmailService{dialer: dialer} return }
go
func NewSMTPEmailService(host string, port int, user string, password string) (service *SMTPEmailService) { dialer := gomail.NewDialer(host, port, user, password) service = &SMTPEmailService{dialer: dialer} return }
[ "func", "NewSMTPEmailService", "(", "host", "string", ",", "port", "int", ",", "user", "string", ",", "password", "string", ")", "(", "service", "*", "SMTPEmailService", ")", "{", "dialer", ":=", "gomail", ".", "NewDialer", "(", "host", ",", "port", ",", ...
//NewSMTPEmailService creates a nes SMTPEmailService
[ "NewSMTPEmailService", "creates", "a", "nes", "SMTPEmailService" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/communication/email.go#L28-L32
14,099
itsyouonline/identityserver
db/user/User.go
GetPublicKeyByLabel
func (u *User) GetPublicKeyByLabel(label string) (publicKey PublicKey, err error) { for _, publicKey = range u.PublicKeys { if publicKey.Label == label { return } } err = errors.New("Could not find PublicKey with label " + label) return }
go
func (u *User) GetPublicKeyByLabel(label string) (publicKey PublicKey, err error) { for _, publicKey = range u.PublicKeys { if publicKey.Label == label { return } } err = errors.New("Could not find PublicKey with label " + label) return }
[ "func", "(", "u", "*", "User", ")", "GetPublicKeyByLabel", "(", "label", "string", ")", "(", "publicKey", "PublicKey", ",", "err", "error", ")", "{", "for", "_", ",", "publicKey", "=", "range", "u", ".", "PublicKeys", "{", "if", "publicKey", ".", "Labe...
// GetPublicKeyByLabel Gets the public key associated with this label
[ "GetPublicKeyByLabel", "Gets", "the", "public", "key", "associated", "with", "this", "label" ]
333d78810c675fe259e970c190f35a5dc5586569
https://github.com/itsyouonline/identityserver/blob/333d78810c675fe259e970c190f35a5dc5586569/db/user/User.go#L98-L106