summaryrefslogtreecommitdiffstats
path: root/model/gitlab
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-02-12 23:44:29 -0500
committerJoramWilander <jwawilander@gmail.com>2016-02-12 23:44:29 -0500
commit6e9bc1ef8fa9c97337541255428b0e8bd68b97e6 (patch)
treeeecb019bccf43ceb89fab0a159f810caadd72fc3 /model/gitlab
parent6cb4f82ee5a17cd1d32ae19c266b78c2cfd604e6 (diff)
downloadchat-6e9bc1ef8fa9c97337541255428b0e8bd68b97e6.tar.gz
chat-6e9bc1ef8fa9c97337541255428b0e8bd68b97e6.tar.bz2
chat-6e9bc1ef8fa9c97337541255428b0e8bd68b97e6.zip
Make sure the GitLab user has the required fields
Diffstat (limited to 'model/gitlab')
-rw-r--r--model/gitlab/gitlab.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/model/gitlab/gitlab.go b/model/gitlab/gitlab.go
index 8b96c64f6..3ca499976 100644
--- a/model/gitlab/gitlab.go
+++ b/model/gitlab/gitlab.go
@@ -67,6 +67,18 @@ func gitLabUserFromJson(data io.Reader) *GitLabUser {
}
}
+func (glu *GitLabUser) IsValid() bool {
+ if glu.Id == 0 {
+ return false
+ }
+
+ if len(glu.Email) == 0 {
+ return false
+ }
+
+ return true
+}
+
func (glu *GitLabUser) getAuthData() string {
return strconv.FormatInt(glu.Id, 10)
}
@@ -76,9 +88,20 @@ func (m *GitLabProvider) GetIdentifier() string {
}
func (m *GitLabProvider) GetUserFromJson(data io.Reader) *model.User {
- return userFromGitLabUser(gitLabUserFromJson(data))
+ glu := gitLabUserFromJson(data)
+ if glu.IsValid() {
+ return userFromGitLabUser(glu)
+ }
+
+ return &model.User{}
}
func (m *GitLabProvider) GetAuthDataFromJson(data io.Reader) string {
- return gitLabUserFromJson(data).getAuthData()
+ glu := gitLabUserFromJson(data)
+
+ if glu.IsValid() {
+ return glu.getAuthData()
+ }
+
+ return ""
}