darkID-prototype/darkID-library-login-example/web/views/login/login.js
darkID-library-login-example/web/views/login/login.jsRaw
1'use strict';
2
3angular.module('app.login', ['ngRoute'])
4
5 .config(['$routeProvider', function($routeProvider) {
6 $routeProvider.when('/login', {
7 templateUrl: 'views/login/login.html',
8 controller: 'LoginCtrl'
9 });
10 }])
11
12 .controller('LoginCtrl', function($scope, $rootScope, $http, $routeParams, toastr) {
13 $rootScope.server = ""
14 $scope.proof = {
15 publicKey: "",
16 clear: "",
17 question: "",
18 answer: ""
19 };
20 $scope.getproof = function() {
21 $http({
22 url: urlapi + 'getproof',
23 method: "POST",
24 headers: {
25 "Content-Type": undefined
26 },
27 data: $scope.proof
28 })
29 .then(function(data) {
30 console.log("data: ");
31 console.log(data.data);
32 $scope.proof = data.data;
33 },
34 function(data) {
35 console.log(data);
36 toastr.error("error: bad darkID PublicKey")
37 });
38
39 };
40 $scope.sendanswer = function() {
41 $http({
42 url: urlapi + 'answerproof',
43 method: "POST",
44 headers: {
45 "Content-Type": undefined
46 },
47 data: $scope.proof
48 })
49 .then(function(data) {
50 console.log("data: ");
51 console.log(data.data);
52 if(data.data=="fail\n") {
53 toastr.error("Proof of darkID failed");
54 }else{
55 toastr.success("You are logged with darkID!");
56 window.location="#!/main";
57 }
58 },
59 function(data) {
60 console.log(data);
61 });
62
63 };
64 });