Minor fixes on login.

stable
Andrey Antukh 2014-06-26 10:02:44 +02:00
parent f6cb1f0fdb
commit 0457399f7e
4 changed files with 46 additions and 29 deletions

View File

@ -21,6 +21,12 @@
taiga = @.taiga taiga = @.taiga
module = angular.module("taigaAuth", ["taigaResources"])
#############################################################################
## Autghentication Service
#############################################################################
class AuthService extends taiga.Service class AuthService extends taiga.Service
@.$inject = ["$rootScope", "$tgStorage", "$tgModel", "$tgHttp", "$tgUrls"] @.$inject = ["$rootScope", "$tgStorage", "$tgModel", "$tgHttp", "$tgUrls"]
@ -63,14 +69,11 @@ class AuthService extends taiga.Service
## Http interface ## Http interface
################### ###################
login: (username, password) -> login: (data) ->
url = @urls.resolve("auth") url = @urls.resolve("auth")
data = { data = _.clone(data, false)
username: username data.type = "normal"
password: password
type: "normal"
}
return @http.post(url, data).then (data, status) => return @http.post(url, data).then (data, status) =>
user = @model.make_model("users", data.data) user = @model.make_model("users", data.data)
@ -119,18 +122,39 @@ class AuthService extends taiga.Service
# @.setUser(user) # @.setUser(user)
# return user # return user
module.service("$tgAuth", AuthService)
class AuthController extends taiga.Controller #############################################################################
@.$inject = ["$scope", "$tgAuth", "$location"] ## Auth related directives (login, reguister, invitation
#############################################################################
constructor: (@scope, @auth, @location) -> LoginDirective = ($auth, $confirm, $location) ->
@scope.form = {username: "", password: ""} link = ($scope, $el, $attrs) ->
$scope.data = {}
form = $el.find("form").checksley()
submit: -> submit = ->
@auth.login(@scope.form.username, @scope.form.password).then (user) => if not form.validate()
#TODO: fix this return
@location.path("/project/project-example-0/backlog")
promise = $auth.login($scope.data)
promise.then (response) ->
# TODO: finish this.
$location.path("/project/project-example-0/backlog")
promise.then null, (response) ->
if response.data._error_message
$confirm.error(response.data._error_message)
$el.on "submit", (event) ->
event.preventDefault()
submit()
$el.on "click", "a.button-login", (event) ->
event.preventDefault()
submit()
return {link:link}
RegisterDirective = ($auth, $confirm) -> RegisterDirective = ($auth, $confirm) ->
@ -161,7 +185,5 @@ RegisterDirective = ($auth, $confirm) ->
return {link:link} return {link:link}
module = angular.module("taigaAuth", ["taigaResources"])
module.service("$tgAuth", AuthService)
module.controller("AuthController", AuthController)
module.directive("tgRegister", ["$tgAuth", "$tgConfirm", RegisterDirective]) module.directive("tgRegister", ["$tgAuth", "$tgConfirm", RegisterDirective])
module.directive("tgLogin", ["$tgAuth", "$tgConfirm", "$location", LoginDirective])

View File

@ -5,7 +5,7 @@ block head
title Taiga Project management web application with scrum in mind! title Taiga Project management web application with scrum in mind!
block content block content
div.wrapper(ng-controller="AuthController as ctrl") div.wrapper
div.login-main div.login-main
div.login-container div.login-container
h1.logo h1.logo
@ -17,6 +17,3 @@ block content
a.icon.icon-delete(href="", title="Close message") a.icon.icon-delete(href="", title="Close message")
include views/modules/login-form include views/modules/login-form
// include views/modules/register-form
// include views/modules/forgot-form
// include views/modules/reset-pass

View File

@ -5,7 +5,7 @@ block head
title Taiga Project management web application with scrum in mind! title Taiga Project management web application with scrum in mind!
block content block content
div.wrapper(ng-controller="AuthController as ctrl") div.wrapper
div.login-main div.login-main
div.login-container div.login-container
h1.logo h1.logo

View File

@ -1,14 +1,12 @@
div.login-form-container div.login-form-container(tg-login)
form.login-form(ng-submit="ctrl.submit()") form.login-form(ng-submit="ctrl.submit()")
fieldset fieldset
input(type="text", name="username", ng-model="form.username", placeholder="User name") input(type="text", name="username", ng-model="data.username", placeholder="User name",
data-required="true")
fieldset.login-password fieldset.login-password
input(type="password", name="password", ng-model="form.password") input(type="password", name="password", ng-model="data.password", data-required="true")
//-This should be hidden when focus on pass // This should be hidden when focus on pass
a.forgot-pass(href="", title="Did you forgot your pass?") Forgot it? a.forgot-pass(href="", title="Did you forgot your pass?") Forgot it?
fieldset
input.remember-me(type="checkbox", checked="checked", id="remember-me")
label(for="remember-me") remember me on this computer
fieldset fieldset
a.button.button-login.button-gray(href="", ng-click="ctrl.submit()", title="Log in") Enter a.button.button-login.button-gray(href="", ng-click="ctrl.submit()", title="Log in") Enter