github.com/cjdelisle/matterfoss@v5.11.1+incompatible/model/switch_request.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 ) 10 11 type SwitchRequest struct { 12 CurrentService string `json:"current_service"` 13 NewService string `json:"new_service"` 14 Email string `json:"email"` 15 Password string `json:"password"` 16 NewPassword string `json:"new_password"` 17 MfaCode string `json:"mfa_code"` 18 LdapLoginId string `json:"ldap_id"` 19 } 20 21 func (o *SwitchRequest) ToJson() string { 22 b, _ := json.Marshal(o) 23 return string(b) 24 } 25 26 func SwitchRequestFromJson(data io.Reader) *SwitchRequest { 27 var o *SwitchRequest 28 json.NewDecoder(data).Decode(&o) 29 return o 30 } 31 32 func (o *SwitchRequest) EmailToOAuth() bool { 33 return o.CurrentService == USER_AUTH_SERVICE_EMAIL && 34 (o.NewService == USER_AUTH_SERVICE_SAML || 35 o.NewService == USER_AUTH_SERVICE_GITLAB || 36 o.NewService == SERVICE_GOOGLE || 37 o.NewService == SERVICE_OFFICE365) 38 } 39 40 func (o *SwitchRequest) OAuthToEmail() bool { 41 return (o.CurrentService == USER_AUTH_SERVICE_SAML || 42 o.CurrentService == USER_AUTH_SERVICE_GITLAB || 43 o.CurrentService == SERVICE_GOOGLE || 44 o.CurrentService == SERVICE_OFFICE365) && o.NewService == USER_AUTH_SERVICE_EMAIL 45 } 46 47 func (o *SwitchRequest) EmailToLdap() bool { 48 return o.CurrentService == USER_AUTH_SERVICE_EMAIL && o.NewService == USER_AUTH_SERVICE_LDAP 49 } 50 51 func (o *SwitchRequest) LdapToEmail() bool { 52 return o.CurrentService == USER_AUTH_SERVICE_LDAP && o.NewService == USER_AUTH_SERVICE_EMAIL 53 }