Skip to content
This repository has been archived by the owner on Sep 18, 2018. It is now read-only.

Commit

Permalink
issue #1 - Quase finalizado a implementação do código reCaptcha com o…
Browse files Browse the repository at this point in the history
… angular.

-> Falta tela de reenvio de recuperação de contas.
  • Loading branch information
carloshenrq committed Aug 2, 2016
1 parent 46b16ac commit e5eb1fe
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 44 deletions.
110 changes: 71 additions & 39 deletions app/Controller/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,23 @@ public static function email(ServerRequestInterface $request, ResponseInterface
// Dados de retorno para informações de erro.
$return = ['error_state' => 0, 'success_state' => false];

// Define informaçõs de erro. (Caso exista)
$return['error_state'] = self::accountChangeEmail(
self::loggedUser()->getUserid(),
$data['email'],
$data['email_new'],
$data['email_conf']
);

$return['success_state'] = $return['error_state'] == 0;
// Adicionado teste para recaptcha para segurança das requisições enviadas ao forms.
if(BRACP_RECAPTCHA_ENABLED && !self::getApp()->checkReCaptcha($data['recaptcha']))
{
$return['error_state'] = 8;
}
else
{
// Define informaçõs de erro. (Caso exista)
$return['error_state'] = self::accountChangeEmail(
self::loggedUser()->getUserid(),
$data['email'],
$data['email_new'],
$data['email_conf']
);

$return['success_state'] = $return['error_state'] == 0;
}

// Responde com um objeto json informando o estado do cadastro.
$response->withJson($return);
Expand All @@ -380,16 +388,24 @@ public static function password(ServerRequestInterface $request, ResponseInterfa
// Dados de retorno para informações de erro.
$return = ['error_state' => 0, 'success_state' => false];

// Define informaçõs de erro. (Caso exista)
$return['error_state'] = self::accountChangePass(
self::loggedUser()->getUserid(),
$data['user_pass'],
$data['user_pass_new'],
$data['user_pass_conf']
);

// // userid, $old_pass, $new_pass, $new_pass_conf
$return['success_state'] = $return['error_state'] == 0;
// Adicionado teste para recaptcha para segurança das requisições enviadas ao forms.
if(BRACP_RECAPTCHA_ENABLED && !self::getApp()->checkReCaptcha($data['recaptcha']))
{
$return['error_state'] = 5;
}
else
{
// Define informaçõs de erro. (Caso exista)
$return['error_state'] = self::accountChangePass(
self::loggedUser()->getUserid(),
$data['user_pass'],
$data['user_pass_new'],
$data['user_pass_conf']
);

// // userid, $old_pass, $new_pass, $new_pass_conf
$return['success_state'] = $return['error_state'] == 0;
}

// Responde com um objeto json informando o estado do cadastro.
$response->withJson($return);
Expand Down Expand Up @@ -439,15 +455,23 @@ public static function confirmation(ServerRequestInterface $request, ResponseInt
// Dados de retorno para informações de erro.
$return = ['error_state' => 0, 'success_state' => false];

// Se ambos estão definidos, a requisição é para re-envio dos dados de confirmação.
if(isset($data['userid']) && isset($data['email']))
$return['error_state'] = self::registerConfirmResend($data['userid'], $data['email']);
// Se código está definido, a requisição é para confirmação da conta.
else if(isset($data['code']))
$return['error_state'] = self::registerConfirmCode($data['code']);

// Define informaçõs de erro. (Caso exista)
$return['success_state'] = $return['error_state'] == 0;
// Adicionado teste para recaptcha para segurança das requisições enviadas ao forms.
if(BRACP_RECAPTCHA_ENABLED && !self::getApp()->checkReCaptcha($data['recaptcha']))
{
$return['error_state'] = 2;
}
else
{
// Se ambos estão definidos, a requisição é para re-envio dos dados de confirmação.
if(isset($data['userid']) && isset($data['email']))
$return['error_state'] = self::registerConfirmResend($data['userid'], $data['email']);
// Se código está definido, a requisição é para confirmação da conta.
else if(isset($data['code']))
$return['error_state'] = self::registerConfirmCode($data['code']);

// Define informaçõs de erro. (Caso exista)
$return['success_state'] = $return['error_state'] == 0;
}

// Responde com um objeto json informando o estado do cadastro.
$response->withJson($return);
Expand All @@ -468,18 +492,26 @@ public static function register(ServerRequestInterface $request, ResponseInterfa
// Inicializa vetor de retorno.
$return = ['error_state' => 0, 'success_state' => false];

// Executa a tentativa de criar a conta do usuário no banco de dados.
$i_create = self::registerAccount(
$data['userid'], $data['user_pass'] , $data['user_pass_conf'],
$data['email'] , $data['email_conf'], $data['sex'],
false, 0
);

// Realiza os testes para saber o retorno do registro.
if($i_create != 0)
$return['error_state'] = $i_create;
// Adicionado teste para recaptcha para segurança das requisições enviadas ao forms.
if(BRACP_RECAPTCHA_ENABLED && !self::getApp()->checkReCaptcha($data['recaptcha']))
{
$return['error_state'] = 6;
}
else
$return['success_state'] = true;
{
// Executa a tentativa de criar a conta do usuário no banco de dados.
$i_create = self::registerAccount(
$data['userid'], $data['user_pass'] , $data['user_pass_conf'],
$data['email'] , $data['email_conf'], $data['sex'],
false, 0
);

// Realiza os testes para saber o retorno do registro.
if($i_create != 0)
$return['error_state'] = $i_create;
else
$return['success_state'] = true;
}

// Responde com um objeto json informando o estado do cadastro.
$response->withJson($return);
Expand Down
19 changes: 14 additions & 5 deletions js/bracp.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ brACPApp.controller('account.register', ['$scope', '$http', function($scope, $ht
$scope.error_state = 0;
$scope.success_state = false;
$scope.accept_terms = false;
$scope.recaptcha_response = null;

$scope.submitRegister = function() {
var urlRegister = document.querySelector('#_BRACP_URL').value + 'account/register';
Expand All @@ -89,7 +90,8 @@ brACPApp.controller('account.register', ['$scope', '$http', function($scope, $ht
'user_pass_conf' : this.user_pass_conf,
'sex' : this.sex,
'email' : this.email,
'email_conf' : this.email_conf
'email_conf' : this.email_conf,
'recaptcha' : this.recaptcha_response
});

$scope.stage = 1;
Expand Down Expand Up @@ -125,12 +127,14 @@ brACPApp.controller('account.register.resend', ['$scope', '$http', function($sco
$scope.has_code = false;
$scope.error_state = 0;
$scope.success_state = false;
$scope.recaptcha_response = null;

$scope.submitResend = function() {
var urlConfirm = document.querySelector('#_BRACP_URL').value + 'account/confirmation';
var params = $.param({
'userid' : this.userid,
'email' : this.email
'email' : this.email,
'recaptcha' : this.recaptcha_response
});

$scope.stage = 1;
Expand All @@ -154,7 +158,8 @@ brACPApp.controller('account.register.resend', ['$scope', '$http', function($sco
$scope.submitConfirm = function() {
var urlConfirm = document.querySelector('#_BRACP_URL').value + 'account/confirmation';
var params = $.param({
'code' : this.code
'code' : this.code,
'recaptcha' : this.recaptcha_response
});

$scope.stage = 1;
Expand Down Expand Up @@ -252,6 +257,7 @@ brACPApp.controller('account.password', ['$scope', '$http', function($scope, $ht
$scope.stage = 0;
$scope.error_state = 0;
$scope.success_state = false;
$scope.recaptcha_response = null;

$scope.passwordInit = function(allowAdminChange, accountLv, adminLevel) {

Expand All @@ -265,7 +271,8 @@ brACPApp.controller('account.password', ['$scope', '$http', function($scope, $ht
var params = $.param({
'user_pass' : this.user_pass,
'user_pass_new' : this.user_pass_new,
'user_pass_conf' : this.user_pass_conf
'user_pass_conf' : this.user_pass_conf,
'recaptcha' : this.recaptcha
});

$scope.stage = 1;
Expand Down Expand Up @@ -299,13 +306,15 @@ brACPApp.controller('account.email', ['$scope', '$http', function($scope, $http)
$scope.stage = 0;
$scope.error_state = 0;
$scope.success_state = false;
$scope.recaptcha_response = null;

$scope.submitMail = function() {
var urlConfirm = document.querySelector('#_BRACP_URL').value + 'account/email';
var params = $.param({
'email' : this.email,
'email_new' : this.email_new,
'email_conf' : this.email_conf
'email_conf' : this.email_conf,
'recaptcha' : this.recaptcha
});

$scope.stage = 1;
Expand Down
5 changes: 5 additions & 0 deletions templates/account.email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<div ng-switch-when="5">@@CHANGEMAIL,ERROR(DELAY)</div>
<div ng-switch-when="6">@@ERRORS(REGEXP)</div>
<div ng-switch-when="7">@@CHANGEMAIL,ERROR(TAKEN)</div>
<div ng-switch-when="8">@@ERRORS(RECAPTCHA)</div>
</div>
</div>

Expand All @@ -49,6 +50,10 @@
<input type="text" ng-model="email_conf" placeholder="@@CHANGEMAIL,HOLDER(CONFIRM)" size="39" maxlength="39" pattern="{$smarty.const.BRACP_REGEXP_EMAIL}" required/>

<input id="_submitMail" type="submit"/>

{if $smarty.const.BRACP_RECAPTCHA_ENABLED eq true}
<div class="recaptcha" ng-model="$parent.recaptcha_response" vc-recaptcha key="'{$smarty.const.BRACP_RECAPTCHA_PUBLIC_KEY}'"></div>
{/if}
</form>
</div>

Expand Down
5 changes: 5 additions & 0 deletions templates/account.password.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<div ng-switch-when="2">@@CHANGEPASS,ERROR(MISMATCH2)</div>
<div ng-switch-when="3">@@CHANGEPASS,ERROR(EQUALS)</div>
<div ng-switch-when="4">@@ERRORS(REGEXP)</div>
<div ng-switch-when="5">@@ERRORS(RECAPTCHA)</div>
</div>
</div>

Expand All @@ -53,6 +54,10 @@
<input type="password" ng-model="user_pass_conf" placeholder="@@CHANGEPASS,HOLDER(CONFIRM_PASSWORD)" size="32" maxlength="32" pattern="{$smarty.const.BRACP_REGEXP_PASSWORD}" required/>

<input id="_submitPassword" type="submit"/>

{if $smarty.const.BRACP_RECAPTCHA_ENABLED eq true}
<div class="recaptcha" ng-model="$parent.recaptcha_response" vc-recaptcha key="'{$smarty.const.BRACP_RECAPTCHA_PUBLIC_KEY}'"></div>
{/if}
</form>
</div>

Expand Down
10 changes: 10 additions & 0 deletions templates/account.register.resend.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<div ng-switch="$parent.error_state">
<div ng-switch-when="-1">@@RESEND,ERROR(DISABLED)</div>
<div ng-switch-when="1">@@RESEND,ERROR(NOACC)</div>
<div ng-switch-when="2">@@ERRORS(RECAPTCHA)</div>
</div>
</div>

Expand All @@ -46,6 +47,10 @@
<input type="text" ng-model="email" placeholder="@@RESEND,HOLDER(EMAIL)" size="39" maxlength="39" pattern="{$smarty.const.BRACP_REGEXP_EMAIL}" required/>

<input id="_submitResend" type="submit"/>

{if $smarty.const.BRACP_RECAPTCHA_ENABLED eq true}
<div class="recaptcha" ng-model="$parent.recaptcha_response" vc-recaptcha key="'{$smarty.const.BRACP_RECAPTCHA_PUBLIC_KEY}'"></div>
{/if}
</form>
</div>

Expand All @@ -54,6 +59,7 @@
<div ng-switch="$parent.error_state">
<div ng-switch-when="-1">@@RESEND,ERROR(DISABLED)</div>
<div ng-switch-when="1">@@RESEND,ERROR(USED)</div>
<div ng-switch-when="2">@@ERRORS(RECAPTCHA)</div>
</div>
</div>

Expand All @@ -68,6 +74,10 @@
<input type="text" ng-model="code" placeholder="@@RESEND,HOLDER(CODE)" maxlength="32" required/>

<input id="_submitConfirm" type="submit"/>

{if $smarty.const.BRACP_RECAPTCHA_ENABLED eq true}
<div class="recaptcha" ng-model="$parent.recaptcha_response" vc-recaptcha key="'{$smarty.const.BRACP_RECAPTCHA_PUBLIC_KEY}'"></div>
{/if}
</form>
</div>

Expand Down
5 changes: 5 additions & 0 deletions templates/account.register.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<div ng-switch-when="3">@@CREATE,ERROR,MISMATCH(EMAIL)</div>
<div ng-switch-when="4">@@CREATE,ERROR,MISMATCH(ADMIN_MODE)</div>
<div ng-switch-when="5">@@ERRORS(REGEXP)</div>
<div ng-switch-when="6">@@ERRORS(RECAPTCHA)</div>
</div>
</div>

Expand All @@ -59,6 +60,10 @@
<input type="text" ng-model="email_conf" placeholder="@@CREATE,HOLDER(EMAIL_CONFIRM)" maxlength="39" pattern="{$smarty.const.BRACP_REGEXP_EMAIL}" required/>

<input id="_submitRegister" type="submit"/>

{if $smarty.const.BRACP_RECAPTCHA_ENABLED eq true}
<div class="recaptcha" ng-model="$parent.recaptcha_response" vc-recaptcha key="'{$smarty.const.BRACP_RECAPTCHA_PUBLIC_KEY}'"></div>
{/if}
</form>
</div>

Expand Down

0 comments on commit e5eb1fe

Please sign in to comment.