This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauth.service.coffee
68 lines (61 loc) · 1.85 KB
/
auth.service.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
Auth = (ENV, $window, AuthToken, $state, $stateParams, $location, $timeout, ApiService) ->
auth0 = new Auth0
domain: ENV.auth0Domain
clientID: ENV.clientId
callbackURL: ENV.auth0Callback
login: (username, password, successCallback, errorCallback) ->
auth0.signin
connection: 'LDAP',
scope: 'openid profile',
username: username,
password: password,
, (err, profile, id_token, access_token, state) ->
if (err)
console.log 'err', err
errorCallback err
else
AuthToken.setToken id_token
successCallback profile, id_token, access_token, state
logout: () ->
AuthToken.removeToken()
$state.transitionTo $state.current, $stateParams,
reload: true
inherit: false
notify: true
register: (reg) ->
# api params
# required: ["firstName", "lastName", "handle", "country", "email"],
# optional: ["password", "socialProviderId", "socialUserName", "socialEmail", "socialEmailVerified", "regSource", "socialUserId", "utm_source", "utm_medium", "utm_campaign"]
url = ENV.API_URL + '/users/'
body =
options:
afterActivationURL: 'https://ios.' + ENV.domain
param:
handle: reg.handle
firstName: reg.firstName
lastName: reg.lastName
country:
isoAlpha3Code: reg.country.value
email: reg.email
age: reg.age
utmSource: reg.utm_source
utmMedium: reg.utm_medium
utmCampaign: reg.utm_campaign
regSource: reg.regSource
credential:
password: reg.password
ApiService.requestHandler 'POST', url, JSON.stringify body, true
isAuthenticated: () ->
!!AuthToken.getToken()
angular.module('lime-topcoder').factory 'Auth', [
'ENV'
'$window'
'AuthToken'
'$state'
'$stateParams'
'$location'
'$timeout'
'ApiService'
Auth
]