Created
January 27, 2017 13:26
-
-
Save salami-art/d1e6273d45f9f9cd562f3610fdbb296c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS IS TOTALLY RENEWED - BE CAREFUL | |
angular.module('pazienti_light').controller "LoginCtrl", ['$scope', 'current_session', 'Session', 'MultiForm', | |
($scope, current_session, Session, MultiForm)-> | |
$scope.MultiForm = MultiForm | |
# INITIALIZING PROFILE | |
$scope.user = | |
email: MultiForm.email || "" | |
password: "" | |
remember_me: true | |
# JUST A FUNCTION TO GET SIGNED UP | |
$scope.login = (user)-> | |
Session.login user | |
] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('pazienti_light').factory("MultiForm", ['$http', ($http)-> | |
return MultiForm = { | |
email_taken: true | |
email: "" | |
checkExistance: (data)-> | |
@email = data.email | |
$http.get("/api/v1/users/0/is_exist?email=" + data.email).success( | |
(has_been_taken)-> | |
console.log(has_been_taken) | |
MultiForm.email_taken = eval(has_been_taken) | |
# if @email_taken | |
# MixpanelPackager.Login().start() | |
# else | |
# MixpanelPackager.Signup().start() | |
) | |
setEmailTaken: (value)-> | |
MultiForm.email_taken = eval(value) | |
} | |
]) | |
angular.module('pazienti_light').controller "RegistrationsCtrl", ['$scope', '$interval', '$timeout', '$http', '$location', '$rootScope', 'Registrations', 'current_session', 'MultiForm', '$modal', 'Flashing', | |
($scope, $interval, $timeout, $http, $location, $rootScope, Registrations, current_session, MultiForm, $modal, Flashing)-> | |
$scope.MultiForm = MultiForm | |
# if current_session.success | |
# $scope.setFlashMessage("wrng", "Hai già effettuato l'accesso :)") | |
# $rootScope.pendingShowRequests = true | |
# $location.url("/") | |
#$scope.MixpanelPackager = MixpanelPackager | |
$scope.email_taken = null | |
if $location.url().indexOf "/users/sign_up" > -1 | |
$scope.email_taken = false | |
if $location.url().indexOf "/users/sign_in" > -1 | |
$scope.email_taken = true | |
$scope.user = | |
email: "" | |
password: "" | |
if window.getParams.reset_password_token? | |
$modal.open("login.reset_password") | |
# if $scope.email_taken? | |
# if $scope.email_taken | |
# MixpanelPackager.Login().start() | |
# else | |
# MixpanelPackager.Signup().start({'User type': 'USER'}) | |
step = $scope.step = 0 | |
$scope.pwdForgottenBox = false | |
$scope.emailSignup = -> | |
$scope.email_signup = true | |
# if $scope.email_taken | |
# MixpanelPackager.Login().useEmail() | |
# MixpanelPackager.Login().withSomething({Method: 'Email'}) | |
# else | |
# MixpanelPackager.Signup().useEmail() | |
# MixpanelPackager.Signup().withSomething({Method: 'Email'}) | |
$scope.switchEmailTaken = (delay=500)-> | |
$timeout(-> | |
$scope.email_taken = !$scope.email_taken | |
,delay) | |
$scope.signMeIn = (user_type=false)-> | |
if $scope.email_taken | |
$scope.login() | |
else | |
$scope.signup(user_type) | |
true | |
# FACEBOOK LOGIN -- | |
# TO BE TESTED OUT | |
fb_check = 0 | |
$scope.facebookLogin = (user_type=false)-> | |
# if $scope.email_taken | |
# MixpanelPackager.Login().facebook() | |
# MixpanelPackager.Login().withSomething({Method: 'Facebook'}) | |
# else | |
# MixpanelPackager.Signup().facebook() | |
# MixpanelPackager.Signup().withSomething({Method: 'Facebook'}) | |
window.popupsuper = popupCenter("/users/auth/facebook?display=popup", 480,320, "Accedi a Pazienti con Facebook") | |
# I HAVE IMPROVED TIMING FUNCTIONS | |
fb_check = $interval(($window)-> | |
if not $window.popupsuper.location? | |
fb_check.clearInterval() | |
if $window.popupsuper isnt undefined and $window.popupsuper.location? and $window.popupsuper.location.pathname? and ($window.popupsuper.location.hash is "#_=_" or $window.popupsuper.location.pathname.indexOf("me") isnt -1) | |
current_session.update( | |
(response)-> | |
if response.sign_in_count > 1 | |
# current_session.user = response | |
$location.url "/me/dash" if $location.url() isnt "/risposte/new" | |
#MixpanelPackager.Login().success() | |
$rootScope.popup.close() | |
else | |
$location.url "/me/dash" | |
#MixpanelPackager.Signup().userType() | |
console.log user_type | |
# if user_type isnt false | |
# $scope.user.type = user_type | |
# $rootScope.session.choose_user_type($scope, true) | |
# $scope.$apply(->) #USING APPLY TO FORCE ANGULAR TO CHECK THE SITUATION | |
) | |
$window.popupsuper.close() | |
fb_check.clearInterval() | |
,10) | |
if $location.url().indexOf('/users/sign_') > -1 | |
current_session.onLogin((current_user, location)-> | |
location.url("/me/dash") | |
) | |
current_session.onSignup((current_user, location)-> | |
location.url "/me/dash" | |
) | |
####LOGIN FUNCTIONS | |
$scope.closeForgottenBox = -> | |
$scope.pwdForgottenBox = false | |
$rootScope.overflowhidden = false | |
$scope.forgot = -> | |
$rootScope.overflowhidden = true | |
$scope.pwdForgottenBox = true | |
$scope.remindPassword = (userEmail=$scope.userEmail)-> | |
$http.post("/api/v1/users/0/reset_password_instruction?email=" + userEmail).success( | |
(r)-> | |
console.log r | |
#if r.success is false | |
#$scope.setFlashMessage("wrng", "L'indirizzo email indicato non esiste") | |
if r.success is true | |
#$scope.setFlashMessage("ok", "Ti abbiamo appena inviato un'email. Segui le istruzioni per impostare una nuova password. ") | |
$scope.userEmail = "" | |
$scope.overflowhidden = false | |
$scope.pwdForgottenBox = false | |
$scope.passwordRequested = true | |
else | |
Flashing.setMessage("L'indirizzo che hai indicato non è registrato") | |
) | |
####SIGNUP FUNCTIONS | |
$scope.signup = (type=false)-> | |
Registrations.signup($scope.user) | |
#MixpanelPackager.Signup().submit() | |
####UTILITIES - THESE ARE QUITE OFTEN AVAILABLE | |
$scope.checkExistance = (data)-> | |
#if $scope.user.email | |
console.log current_session.user | |
#if current_session.user isnt null and current_session.user.email | |
console.log "#################################" | |
console.log data | |
$http.get("/api/v1/users/0/is_exist?email=" + data.email).success( | |
(has_been_taken)-> | |
if MultiForm.email_taken isnt eval(has_been_taken) | |
MultiForm.email_taken = eval(has_been_taken) | |
# if MultiForm.email_taken | |
# MixpanelPackager.Login().start() | |
# else | |
# MixpanelPackager.Signup().start() | |
) | |
$scope.checkEmail = ()-> | |
# if $scope.user.email | |
# if $scope.email_taken | |
# MixpanelPackager.Login().useEmail() | |
# MixpanelPackager.Login().insertEmail() | |
# else | |
# MixpanelPackager.Signup().useEmail() | |
# MixpanelPackager.Signup().insertEmail() | |
$scope.checkPassword = ()-> | |
#if $scope.user.password? | |
# if $scope.email_taken | |
# MixpanelPackager.Login().insertPassword() | |
# else | |
# MixpanelPackager.Signup().insertPassword() | |
# $scope.is = (what, value)-> | |
# what is value | |
$scope.setEmailTaken = (fl)-> | |
$scope.email_taken = fl | |
$scope.email_taken = true | |
] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Login Modal --> | |
<div class="modal fade" id="login_modal" role="dialog"> | |
<div class="modal-dialog"> | |
<!-- Modal content--> | |
<div class="modal-content"> | |
<div class="modal-body"> | |
<form name="user_signup_form" | |
ng-submit="login(user)" | |
class="signup for_blinds in_the_middle signupform" | |
ng-controller="UsersSignupCtrl" | |
> | |
<div class="row"> | |
<div class="col-md-12"> | |
<h4 class="small-modal-heading">Entra con il tuo indirizzo e-mail:</h4> | |
<div class="form-group"> | |
<!-- LABEL FOR BAD EMAIL --> | |
<span class="tooltip_test" | |
data-tooltip="Indirizzo email non valido" | |
ng-show="user_signup_form.email.$error.email"> | |
</span> | |
<input id="username" class="form-control" name="email" | |
type="email" | |
tabindex="10" | |
ng-blur-filled="binding.MultiForm.checkExistance(user)" | |
ng-model="user.email" | |
placeholder="Indirizzo email" | |
autofocus | |
autocomplete="off" | |
ng-placeholder="Indirizzo email" | |
required> | |
</div> | |
<div class="form-group"> | |
<!-- LABEL FOR BAD PASSWORD --> | |
<span class="tooltip_test" | |
data-tooltip="Password troppo corta" | |
ng-show="user_signup_form.pwd.$error.minlength"> | |
</span> | |
<input placeholder="Password" type="password" name="password" id="password" class="form-control" | |
ng-minlength="6" | |
tabindex="11" | |
ng-blur="checkPassword()" | |
ng-model="user.password" | |
autocomplete="off" | |
autofocus | |
ng-placeholder="Password"> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col-md-7"> | |
<div class="checkbox"> | |
<label for="user_remember_me" | |
class="rememberme boolean optional control-label" | |
ng-show="MultiForm.email_taken" | |
style="display: inline-block; color: #888; font-size: 12px;"> | |
<input id="user_remember_me" ng-model="user.remember_me" type="checkbox"> | |
Sempre connesso | |
</label> | |
</div> | |
<div> | |
<a class="modal-link highlight" data-dismiss="modal" data-toggle="modal" data-target="#register_modal" onclick="rememberModalChoiceLogin()">Register now</a> | |
<span class="pipe">|</span> | |
<a href="javascript:void(0)" ng-click="$modal.open('login.request_password')" class="modal-link">Ti sei dimenticato?</a> | |
</div> | |
</div> | |
<div class="col-sm-5"> | |
<button type="submit" class="btn btn-borders btn-quaternary text-uppercase font-weight-bold">Login</button> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script type="text/javascript" charset="utf-8"> | |
var rememberModalChoiceLogin = function() { | |
var registerBackBtn = document.getElementById('modal_btn_back'); | |
registerBackBtn.setAttribute('data-target', '#login_modal'); | |
registerBackBtn.setAttribute('data-toggle', 'modal'); | |
} | |
var flushChoiceRegister = function() { | |
var registerBackBtn = document.getElementById('modal_btn_back'); | |
registerBackBtn.setAttribute('data-target', ''); | |
registerBackBtn.setAttribute('data-toggle', ''); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment