summaryrefslogtreecommitdiffstats
path: root/model/switch_request.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-10 08:19:49 -0400
committerChristopher Speller <crspeller@gmail.com>2017-04-10 08:19:49 -0400
commitdfc6db737411bd4ad68a803be5182f06055a1769 (patch)
tree375d93b8d1d8b1384988dc708c9f337e0ea2366c /model/switch_request.go
parent7b77bcf87e85330a1f7f0b2a2dcbf71326bf2fba (diff)
downloadchat-dfc6db737411bd4ad68a803be5182f06055a1769.tar.gz
chat-dfc6db737411bd4ad68a803be5182f06055a1769.tar.bz2
chat-dfc6db737411bd4ad68a803be5182f06055a1769.zip
Refactor switching login type code into app layer and add v4 endpoint (#6000)
* Refactor switching login type code into app layer and add v4 endpoint * Fix unit test
Diffstat (limited to 'model/switch_request.go')
-rw-r--r--model/switch_request.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/model/switch_request.go b/model/switch_request.go
new file mode 100644
index 000000000..44fbb27a9
--- /dev/null
+++ b/model/switch_request.go
@@ -0,0 +1,62 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type SwitchRequest struct {
+ CurrentService string `json:"current_service"`
+ NewService string `json:"new_service"`
+ Email string `json:"email"`
+ Password string `json:"current_password"`
+ NewPassword string `json:"new_password"`
+ MfaCode string `json:"mfa_code"`
+ LdapId string `json:"ldap_id"`
+}
+
+func (o *SwitchRequest) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func SwitchRequestFromJson(data io.Reader) *SwitchRequest {
+ decoder := json.NewDecoder(data)
+ var o SwitchRequest
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}
+
+func (o *SwitchRequest) EmailToOAuth() bool {
+ return o.CurrentService == USER_AUTH_SERVICE_EMAIL &&
+ (o.NewService == USER_AUTH_SERVICE_SAML ||
+ o.NewService == USER_AUTH_SERVICE_GITLAB ||
+ o.NewService == SERVICE_GOOGLE ||
+ o.NewService == SERVICE_OFFICE365)
+}
+
+func (o *SwitchRequest) OAuthToEmail() bool {
+ return (o.CurrentService == USER_AUTH_SERVICE_SAML ||
+ o.CurrentService == USER_AUTH_SERVICE_GITLAB ||
+ o.CurrentService == SERVICE_GOOGLE ||
+ o.CurrentService == SERVICE_OFFICE365) && o.NewService == USER_AUTH_SERVICE_EMAIL
+}
+
+func (o *SwitchRequest) EmailToLdap() bool {
+ return o.CurrentService == USER_AUTH_SERVICE_EMAIL && o.NewService == USER_AUTH_SERVICE_LDAP
+}
+
+func (o *SwitchRequest) LdapToEmail() bool {
+ return o.CurrentService == USER_AUTH_SERVICE_LDAP && o.NewService == USER_AUTH_SERVICE_EMAIL
+}