summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/client4.go10
-rw-r--r--model/switch_request.go62
-rw-r--r--model/switch_request_test.go19
3 files changed, 91 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 634c477e2..6d4772431 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -409,6 +409,16 @@ func (c *Client4) Logout() (bool, *Response) {
}
}
+// SwitchAccountType changes a user's login type from one type to another.
+func (c *Client4) SwitchAccountType(switchRequest *SwitchRequest) (string, *Response) {
+ if r, err := c.DoApiPost(c.GetUsersRoute()+"/login/switch", switchRequest.ToJson()); err != nil {
+ return "", &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return MapFromJson(r.Body)["follow_link"], BuildResponse(r)
+ }
+}
+
// User Section
// CreateUser creates a user in the system based on the provided user struct.
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
+}
diff --git a/model/switch_request_test.go b/model/switch_request_test.go
new file mode 100644
index 000000000..b85846f78
--- /dev/null
+++ b/model/switch_request_test.go
@@ -0,0 +1,19 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestSwitchRequestJson(t *testing.T) {
+ o := SwitchRequest{Email: NewId(), Password: NewId()}
+ json := o.ToJson()
+ ro := SwitchRequestFromJson(strings.NewReader(json))
+
+ if o.Email != ro.Email {
+ t.Fatal("Emails do not match")
+ }
+}