Commit a6476653 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Usa RestManager en vistas de reseteo de password

parent f2b9adc3
Loading
Loading
Loading
Loading
+26 −33
Original line number Diff line number Diff line
@@ -4,37 +4,34 @@ define([
	, "app/redmicConfig"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/request"
	, "dojo/text!./templates/ConfirmResetting.html"
	, 'redmic/modules/base/_Store'
], function(
	alertify
	, _ExternalUserBaseView
	, redmicConfig
	, declare
	, lang
	, request
	, template
	, _Store
) {

	return declare(_ExternalUserBaseView, {
	return declare([_ExternalUserBaseView, _Store], {
		//	summary:
		//		Vista de confimación de resetting password
		//
		//	description:
		//		Permite resetear la contraseña a partir de un enlace enviado al correo electrónico
		//		asociado a la cuenta.
		//		Vista que permite resetear la contraseña de un usuario, a partir de un enlace enviado al correo
		//		electrónico asociado a dicha cuenta.

		constructor: function(args) {

			this.config = {
				ownChannel: "confirmResetting",
				templateProps:  {
					templateString: template,
					i18n: this.i18n,
					_onSubmitResetting: lang.hitch(this, this._onSubmitResetting),
					_onCloseResetting: lang.hitch(this, this._onCloseResetting),
					_confirmValidator: lang.hitch(this, this._confirmValidator)
				},
				ownChannel: "confirmResetting"
				}
			};

			lang.mixin(this, this.config, args);
@@ -82,22 +79,26 @@ define([

			envDfd.then(lang.hitch(this, function(data, envData) {

				var target = redmicConfig.getServiceUrl(redmicConfig.services.resettingSetPassword, envData);
				this.target = redmicConfig.getServiceUrl(redmicConfig.services.resettingSetPassword, envData);

				request(target, {
					handleAs: "json",
					method: "POST",
					data: JSON.stringify(data),
					headers: {
						"Content-Type": "application/json",
						"Accept": "application/javascript, application/json"
					}
				}).then(
					lang.hitch(this, this._handleResponse),
					lang.hitch(this, this._handleError));
				this._emitEvt('REQUEST', {
					target: this.target,
					method: 'POST',
					query: data
				});
			}, data));
		},

		_dataAvailable: function(res, resWrapper) {

			this._handleResponse(res.data);
		},

		_errorAvailable: function(error, status, resWrapper) {

			this._handleError(resWrapper.res.data);
		},

		_handleResponse: function(result) {
			//	summary:
			//		Función que maneja la respuesta del recovery,
@@ -107,11 +108,7 @@ define([
			//		callback private
			//

			if (result.success) {
			alertify.alert(this.i18n.success, this.i18n.successResetting, this._goBack);
			} else {
				this._handleError(result.error);
			}
		},

		_handleError: function(error) {
@@ -137,10 +134,6 @@ define([
				error = error[0];
			}

			if (error.response && error.response.data) {
				error = error.response.data.error;
			}

			var msg = error.description;

			this._emitEvt('TRACK', {
+27 −35
Original line number Diff line number Diff line
@@ -4,35 +4,32 @@ define([
	, "app/redmicConfig"
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/request"
	, "dojo/text!./templates/Resetting.html"
	, 'redmic/modules/base/_Store'
], function(
	alertify
	, _ExternalUserBaseView
	, redmicConfig
	, declare
	, lang
	, request
	, template
	, _Store
) {

	return declare(_ExternalUserBaseView, {
	return declare([_ExternalUserBaseView, _Store], {
		//	summary:
		// 	Vista de register
		//
		// description:
		// 	Permite registrarse en la aplicación
		//		Vista que permite solicitar el reseteo de la contraseña de usuario

		constructor: function(args) {

			this.config = {
				ownChannel: "resetting",
				templateProps:  {
					templateString: template,
					i18n: this.i18n,
					_onCloseResettingPassword: lang.hitch(this, this._onCloseResettingPassword),
					_onSubmitResettingPassword: lang.hitch(this, this._onSubmitResettingPassword)
				},
				ownChannel: "resetting"
				}
			};

			lang.mixin(this, this.config, args);
@@ -94,22 +91,26 @@ define([

			envDfd.then(lang.hitch(this, function(value, envData) {

				var target = redmicConfig.getServiceUrl(redmicConfig.services.resettingRequest, envData);
				this.target = redmicConfig.getServiceUrl(redmicConfig.services.resettingRequest, envData);

				request(target, {
					handleAs: "json",
					method: "POST",
					data: JSON.stringify(value),
					headers: {
						"Content-Type": "application/json",
						"Accept": "application/javascript, application/json"
					}
				}).then(
					lang.hitch(this, this._handleResponse),
					lang.hitch(this, this._handleError));
				this._emitEvt('REQUEST', {
					target: this.target,
					method: 'POST',
					query: value
				});
			}, value));
		},

		_dataAvailable: function(res, resWrapper) {

			this._handleResponse(res.data);
		},

		_errorAvailable: function(error, status, resWrapper) {

			this._handleError(resWrapper.res.data);
		},

		_handleResponse: function(result) {
			//	summary:
			//		Función que maneja la respuesta del registro,
@@ -119,11 +120,7 @@ define([
			//		callback private
			//

			if (result.success) {
			alertify.alert(this.i18n.success, this.i18n.resettingInfo, this._goBack);
			} else {
				this._handleError(result.error);
			}
		},

		_handleError: function(error) {
@@ -144,11 +141,6 @@ define([
			//	tags:
			//		callback private

			// TODO: cambiar cuando esten unificados los errores de la api
			if (error.response && error.response.data) {
				error = error.response.data.error;
			}

			var msg = error.description;

			this._emitEvt('TRACK', {