Skip to content

Commit

Permalink
Ajout d'une page de profil avec pour feature le changement de mot de …
Browse files Browse the repository at this point in the history
…passe
  • Loading branch information
MyVirtualStoryBook committed Jan 8, 2016
1 parent 09caf38 commit 15c01c0
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 2 deletions.
5 changes: 5 additions & 0 deletions public/angularApp/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ var myVirtualStoryBookApp = angular
controller:"PublishBookController",
templateUrl:"app/feature/share/view/PublishBook.html"
})
.state('app.profile', {
url: "/profile",
controller:"ProfileController",
templateUrl:"app/feature/profile/view/Profile.html"
})
.state("sanbox", {
url: "/sandbox",
controller:"SandboxController",
Expand Down
16 changes: 14 additions & 2 deletions public/angularApp/app/feature/common/service/ConnectionService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
myVirtualStoryBookApp.service("ConnectionService", ['$http','$window',
function($http,$window){
myVirtualStoryBookApp.service("ConnectionService", ['$http','$window','PlayerService',
function($http,$window, PlayerService){

var service = {};

Expand All @@ -26,6 +26,18 @@ myVirtualStoryBookApp.service("ConnectionService", ['$http','$window',
$window.localStorage.removeItem('token');
}

service.changePassword = function(passwords){
var credentials = {};
credentials.passwords = {};
credentials.passwords.new = CryptoJS.SHA512(passwords.new);
credentials.passwords.confirmation = CryptoJS.SHA512(passwords.confirmation);
credentials.passwords.old = CryptoJS.SHA512(passwords.old);
credentials.passwords.new = credentials.passwords.new.toString(CryptoJS.enc.Base64);
credentials.passwords.confirmation = credentials.passwords.confirmation.toString(CryptoJS.enc.Base64);
credentials.passwords.old = credentials.passwords.old.toString(CryptoJS.enc.Base64);
return $http.patch("/api/player/"+PlayerService.player.data._id, credentials);
}

return service;
}
]);
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<li ng-show="loaders.books"><a><i class="fa fa-refresh"></i>Rafraichissement des livres</a></li>
</ul>
</li>
<li class="treeview">
<a ui-sref="app.profile">
<i class="fa fa-user"></i> <span>Mon profil</span></i>
</a>
</li>
</ul>
</section>
<!-- /.sidebar -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

angular.module('myVirtualStoryBookApp')
.controller('ProfileController', function ($scope, $state, $location, $window, ConnectionService, PlayerService) {

if ($location.protocol() != 'https'){
$window.location.href = $location.absUrl().replace('http', 'https');
};

$scope.state = 'init';

$scope.changePassword = function(passwords){
if($scope.loginForm.$valid){
$scope.state = 'sending';
ConnectionService.changePassword(passwords).success(function(player){
$scope.state = 'success';
}).error($scope._displayError);
}
}

$scope._displayError = function(response){
$scope.displayMessage = true;
$scope.state= 'error';
$scope.displayMessageText = response.message;
}

});
50 changes: 50 additions & 0 deletions public/angularApp/app/feature/profile/view/Profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="content-wrapper">
<section class="content-header">
<h1>Mon profil</h1>
<ol class="breadcrumb">
<li><a ui-sref="app.play.books">MyVirtualStoryBook</a></li>
<li class="active">Mon profil</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="row">
<div class="col-xs-6">
<div>
<div class="box md-whiteframe-z1">
<div class="box-header">
<h3 class="box-title">Changer de mot de passe</h3>
</div><!-- /.box-header -->
<div class="box-body row">
<div class="col-xs-12">
<form name="loginForm">
<div class="input-group margin-top" style="width:100%">
<label>Nouveau mot de passe</label>
<input type="password" max="20" name="new" class="form-control" placeholder="Nouveau mot de passe" ng-model="passwords.new" ng-change="displayMessage = false" required>
</div>
<div class="input-group margin-top" style="width:100%">
<label>Confirmation</label>
<input type="password" max="20" name="confirmation" class="form-control" placeholder="Confirmation" ng-model="passwords.confirmation" ng-change="displayMessage = false" required>
</div>
<div class="input-group margin-top" style="width:100%">
<label>Ancien mot de passe</label>
<input type="password" max="20" name="old" class="form-control" placeholder="Ancien mot de passe" ng-model="passwords.old" ng-change="displayMessage = false" required>
</div>
<div class="row margin-top">
<div class="col-xs-12">
<button ng-show="state === 'init'" style="width:100%" type="submit" ng-click="changePassword(passwords)" class="btn btn-primary">Changer de mot de passe</md-button>
<button ng-show="state === 'sending'" disabled style="width:100%" type="submit" class="btn btn-warning">Verification<span class="fa fa-spinner fa-spin"></span></md-button>
<button ng-show="state === 'success'" disabled style="width:100%" type="submit" class="btn btn-success">Mot de passe changé <span class="fa fa-check"></span></md-button>
<button ng-show="state === 'error'" style="width:100%" type="submit" ng-click="changePassword(passwords)" class="btn btn-danger">{{displayMessageText}}</md-button>
</div><!-- /.col -->
</div>
</form>
</div>
</div><!-- /.box-body -->
</div>
</div>
</div>
</div>
</section><!-- /.content -->
</div>
1 change: 1 addition & 0 deletions public/angularApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<!-- Controllers -->
<script src="app/app.js"></script>
<script src="app/feature/common/controller/BaseController.js"></script>
<script src="app/feature/profile/controller/ProfileController.js"></script>
<script src="app/feature/portal/controller/RecoverController.js"></script>
<script src="app/feature/portal/controller/SignInController.js"></script>
<script src="app/feature/portal/controller/SignUpController.js"></script>
Expand Down
27 changes: 27 additions & 0 deletions routes/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ router.get('/:playerId', function(req, res, next) {
});
});

router.patch('/:playerId',function(req,res,next){
Player.findOne({_id:req.params.playerId}).then(function(player){
var hadError = false;
if(req.body.passwords){
if(req.body.passwords.confirmation === req.body.passwords.new && req.body.passwords.old == player.password){
player.password = req.body.passwords.new;
}else{
hadError = true;
if(req.body.passwords.confirmation !== req.body.passwords.new){
res.status(400).send({message:'Les mots de passe ne correspondent pas, Réessayez'});
}else{
res.status(403).send({message:'Mauvais mot de passe, Réessayez'});
}
}
}
if(!hadError){
player.save().then(function(){
res.sendStatus(200);
},function(err){
next(err)
})
}
},function(err){
next(err)
})
})

router.post('/', function(req, res, next) {

var player = new Player();
Expand Down

0 comments on commit 15c01c0

Please sign in to comment.