Task #1424: Login with GitHub
parent
976dd0c973
commit
b8bf8902d1
|
@ -218,6 +218,7 @@ modules = [
|
|||
"taigaUserSettings",
|
||||
"taigaFeedback",
|
||||
"taigaPlugins",
|
||||
"taigaIntegrations",
|
||||
|
||||
# Vendor modules
|
||||
"ngRoute",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
###
|
||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# File: modules/integrations.coffee
|
||||
###
|
||||
|
||||
module = angular.module("taigaIntegrations", [])
|
|
@ -0,0 +1,110 @@
|
|||
###
|
||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# File: modules/integrations/github.coffee
|
||||
###
|
||||
|
||||
taiga = @.taiga
|
||||
|
||||
module = angular.module("taigaIntegrations")
|
||||
|
||||
AUTH_URL = "https://github.com/login/oauth/authorize"
|
||||
|
||||
|
||||
#############################################################################
|
||||
## User story team requirements button directive
|
||||
#############################################################################
|
||||
|
||||
GithubLoginButtonDirective = ($window, $params, $location, $config, $events, $confirm, $auth, $navUrls, $loader) ->
|
||||
# Login or registar a user with his/her github account.
|
||||
#
|
||||
# Example:
|
||||
# tg-github-login-button()
|
||||
#
|
||||
# Requirements:
|
||||
# - ...
|
||||
|
||||
template = """
|
||||
<a class="button button-github" href="" title="Enter with your github account">
|
||||
<span class="icon icon-github"></span>
|
||||
<span>Login with Github</span>
|
||||
</a>
|
||||
""" #TODO: i18n
|
||||
|
||||
link = ($scope, $el, $attrs) ->
|
||||
redirectToUri = $location.absUrl()
|
||||
clientId = $config.get("gitHubClientId", null)
|
||||
|
||||
renderGitHubButton = ->
|
||||
$el.html(template) if clientId
|
||||
|
||||
loginOnSuccess = (response) ->
|
||||
if $params.next and $params.next != $navUrls.resolve("login")
|
||||
nextUrl = $params.next
|
||||
else
|
||||
nextUrl = $navUrls.resolve("home")
|
||||
|
||||
$events.setupConnection()
|
||||
|
||||
$location.search("next", null)
|
||||
$location.search("token", null)
|
||||
$location.search("state", null)
|
||||
$location.search("code", null)
|
||||
$location.path(nextUrl)
|
||||
|
||||
loginOnError = (response) ->
|
||||
$location.search("state", null)
|
||||
$location.search("code", null)
|
||||
$loader.pageLoaded()
|
||||
|
||||
if response.data.error_message
|
||||
$confirm.notify("light-error", response.data.error_message )
|
||||
else
|
||||
$confirm.notify("light-error", "Our Oompa Loompas have not been able to get you
|
||||
credentials from GitHub.") #TODO: i18n
|
||||
|
||||
loginWithGitHubAccount = ->
|
||||
type = $params.state
|
||||
code = $params.code
|
||||
token = $params.token
|
||||
|
||||
return if not (type == "github" and code)
|
||||
$loader.start()
|
||||
|
||||
data = {code: code, token: token}
|
||||
$auth.login(data, type).then(loginOnSuccess, loginOnError)
|
||||
|
||||
renderGitHubButton()
|
||||
loginWithGitHubAccount()
|
||||
|
||||
$el.on "click", ".button-github", (event) ->
|
||||
url = "#{AUTH_URL}?client_id=#{clientId}&redirect_uri=#{redirectToUri}&state=github&scope=user:email"
|
||||
$window.location.href = url
|
||||
|
||||
$scope.$on "$destroy", ->
|
||||
$el.off()
|
||||
|
||||
return {
|
||||
link: link
|
||||
restrict: "EA"
|
||||
template: ""
|
||||
}
|
||||
|
||||
module.directive("tgGithubLoginButton", ["$window", '$routeParams', "$tgLocation", "$tgConfig", "$tgEvents",
|
||||
"$tgConfirm", "$tgAuth", "$tgNavUrls", "tgLoader",
|
||||
GithubLoginButtonDirective])
|
|
@ -10,3 +10,5 @@ form.login-form
|
|||
fieldset
|
||||
a.button.button-login.button-gray(href="", title="Log in") Enter
|
||||
input(type="submit", style="display:none")
|
||||
|
||||
fieldset(tg-github-login-button)
|
||||
|
|
|
@ -23,10 +23,4 @@ form.register-form
|
|||
a.button.button-register.button-gray(href="", title="Sign up") Sign up
|
||||
input(type="submit", style="display:none")
|
||||
|
||||
fieldset
|
||||
a.button.button-github(href="", title="Enter with your github account")
|
||||
span.icon.icon-github
|
||||
span Sign Up with Github
|
||||
input(type="submit", style="display:none")
|
||||
|
||||
tg-terms-notice
|
||||
|
|
|
@ -13,10 +13,6 @@ div.login-form-container(tg-login)
|
|||
a.button.button-login.button-gray(href="", title="Sign in") Sign in
|
||||
input(type="submit", style="display:none")
|
||||
|
||||
fieldset
|
||||
a.button.button-github(href="", title="enter with your github account")
|
||||
span.icon.icon-github
|
||||
span Login with Github
|
||||
input(type="submit", style="display:none")
|
||||
fieldset(tg-github-login-button)
|
||||
|
||||
tg-public-register-message
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
"feedbackEnabled": true,
|
||||
"privacyPolicyUrl": null,
|
||||
"termsOfServiceUrl": null,
|
||||
"maxUploadFileSize": null
|
||||
"maxUploadFileSize": null,
|
||||
"gitHubClientId": null
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ paths.coffee = [
|
|||
paths.app + "coffee/modules/base/*.coffee",
|
||||
paths.app + "coffee/modules/resources/*.coffee",
|
||||
paths.app + "coffee/modules/user-settings/*.coffee"
|
||||
paths.app + "coffee/modules/integrations/*.coffee"
|
||||
paths.app + "plugins/**/*.coffee"
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue