UserConfig.js revision 2d7019e19039fd083850f76e54b6b26a7b06a8f2
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington/* @license
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington *
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * Copyright © 2011 ForgeRock AS. All rights reserved.
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington *
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * The contents of this file are subject to the terms
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * of the Common Development and Distribution License
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * (the License). You may not use this file except in
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * compliance with the License.
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington *
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * You can obtain a copy of the License at
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * http://forgerock.org/license/CDDLv1.0.html
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * See the License for the specific language governing
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * permission and limitations under the License.
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington *
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * When distributing Covered Code, include this CDDL
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * Header Notice in each file and include the License file
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * at http://forgerock.org/license/CDDLv1.0.html
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * If applicable, add the following below the CDDL Header,
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * with the fields enclosed by brackets [] replaced by
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * your own identifying information:
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * "Portions Copyrighted [year] [name of copyright owner]"
5d4589530d1353fdd627ab216a1cdcbcaf6b705ejenkins */
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington/*global define*/
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington/**
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington * @author yaromin
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington */
15f60c5ba586de69e94c6045e9bf91103e924020James Phillpottsdefine("config/process/UserConfig",["app/util/Constants", "app/comp/common/eventmanager/EventManager"],
15f60c5ba586de69e94c6045e9bf91103e924020James Phillpotts function(constants, eventManager) {
15f60c5ba586de69e94c6045e9bf91103e924020James Phillpotts var obj =
15f60c5ba586de69e94c6045e9bf91103e924020James Phillpotts [
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington {
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington startEvent: constants.FORGOTTEN_PASSWORD_CHANGED_SUCCESSFULLY,
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington description: "",
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington dependencies: [
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington "app/comp/common/messages/MessagesCtrl"
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington ],
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington processDescription: function(event, messagesCtrl) {
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington messagesCtrl.displayMessage('info', 'Password has been changed');
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington eventManager.sendEvent(constants.EVENT_LOGIN_REQUEST, { userName: event.userName, password: event.password});
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington }
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington },
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington {
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington startEvent: constants.EVENT_AUTHENTICATED,
a6fc9ae6bd096a653649fdf8e4189f102dd4cdf2Phill Cunnington description: "",
a6fc9ae6bd096a653649fdf8e4189f102dd4cdf2Phill Cunnington dependencies: [],
a6fc9ae6bd096a653649fdf8e4189f102dd4cdf2Phill Cunnington processDescription: function(event) {
a6fc9ae6bd096a653649fdf8e4189f102dd4cdf2Phill Cunnington eventManager.sendEvent(constants.EVENT_SUCCESFULY_LOGGGED_IN, event.uid);
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts }
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts },
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts {
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts startEvent: constants.EVENT_LOGIN_REQUEST,
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts description: "",
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts dependencies: [
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts "app/comp/user/login/LoginCtrl"
6b055fbf69118e3dee2cef69195b41f54029e09eJames Phillpotts ],
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington processDescription: function(event, loginCtrl) {
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington loginCtrl.loginUser(event.userName, event.password);
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington }
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington },
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington {
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington startEvent: constants.EVENT_USER_REGISTRATION_ERROR,
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington description: "User registration error",
9dc0bc74a8acbd729d3d316f53c20901662d0283Phill Cunnington dependencies: [
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington "app/comp/common/messages/MessagesCtrl"
568e7121664e2ad34a90bf97ae9129134a8ce408Phill Cunnington ],
d72b59ef0fcc0226a5a655ad967e4c24729afa3ePhill Cunnington processDescription: function(event, messagesCtrl) {
messagesCtrl.displayMessage('error', event.causeDescription);
}
},
{
startEvent: constants.EVENT_USER_PROFILE_UPDATE_FAILED,
description: "",
dependencies: [
"app/comp/common/messages/MessagesCtrl"
],
processDescription: function(event, messagesCtrl) {
messagesCtrl.displayMessage('error', 'Problem during profile update');
}
},
{
startEvent: constants.EVENT_USER_PROFILE_UPDATED_SUCCESSFULY,
description: "",
dependencies: [
"app/comp/common/messages/MessagesCtrl"
],
processDescription: function(event, messagesCtrl) {
messagesCtrl.displayMessage('info', 'Profile has been updated');
}
},
{
startEvent: constants.EVENT_USER_SUCCESSFULY_REGISTERED,
description: "User registered",
dependencies: [
"app/comp/common/messages/MessagesCtrl",
"app/comp/common/breadcrumbs/BreadcrumbsCtrl"
],
processDescription: function(event, messagesCtrl, breadcrumbsCtrl) {
messagesCtrl.displayMessage('info', 'User has been registered successfully');
if(event.selfRegistration) {
eventManager.sendEvent(constants.EVENT_LOGIN_REQUEST, { userName: event.user.userName, password: event.user.password});
} else {
breadcrumbsCtrl.goBack();
}
}
},
{
startEvent: constants.EVENT_SHOW_PROFILE_REQUEST,
description: "",
dependencies: [
"app/comp/common/breadcrumbs/BreadcrumbsCtrl",
"app/comp/user/profile/ProfileCtrl"
],
processDescription: function(event,breadCrumbsCtrl, profileCtrl) {
breadCrumbsCtrl.clearPath();
profileCtrl.init(constants.MODE_USER);
}
},
{
startEvent: constants.EVENT_SELF_REGISTRATION_REQUEST,
description: "Self registration request",
dependencies: [
"app/comp/common/breadcrumbs/BreadcrumbsCtrl",
"app/comp/user/registration/RegistrationCtrl"
],
processDescription: function(event, breadcrumbsCtrl, registrationCtrl) {
breadcrumbsCtrl.set('Registration');
registrationCtrl.init();
}
},
{
startEvent: constants.EVENT_FORGOTTEN_SHOW_REQUEST,
description: "",
dependencies: [
"app/comp/user/forgottenpassword/ForgottenPasswordDialogCtrl"
],
processDescription: function(event, forgottenPasswordDialogCtrl) {
forgottenPasswordDialogCtrl.init(event);
}
},
{
startEvent: constants.EVENT_PROFILE_INITIALIZATION,
description: "",
dependencies: [
"app/comp/common/breadcrumbs/BreadcrumbsCtrl"
],
processDescription: function(event, breadcrumbsCtrl) {
breadcrumbsCtrl.set(event.profileName);
}
},
{
startEvent: constants.EVENT_SUCCESFULY_LOGGGED_IN,
description: "",
dependencies: [
"app/comp/user/delegates/UserDelegate",
"app/comp/main/Configuration",
"app/comp/user/profile/ProfileCtrl",
"app/comp/user/login/LoginCtrl",
"app/comp/common/messages/MessagesCtrl",
"app/comp/main/Configuration",
"app/comp/common/navigation/NavigationCtrl"
],
processDescription: function(userName, userDelegate, conf, profileCtrl, loginCtrl, messagesCtrl, appConfiguration, navigationCtrl) {
eventManager.sendEvent(constants.EVENT_AUTHENTICATION_DATA_CHANGED, { anonymousMode: false});
userDelegate.getForUserName(
userName,
function(user) {
conf.setProperty('loggedUser', user);
if(appConfiguration.forceUserRole === constants.MODE_ADMIN || user.role === constants.MODE_ADMIN) {
eventManager.sendEvent(constants.EVENT_SWITCH_VIEW_REQUEST, {viewId: "app/comp/admin/usermanagement/UsersCtrl"});
} else {
profileCtrl.init(constants.MODE_USER);
}
navigationCtrl.init(user.role);
loginCtrl.afterSuccessfulLogin(user);
messagesCtrl.displayMessage('info', 'You have been successfully logged in.');
},
function() { messagesCtrl.displayMessage('error', 'Error fetching user data');
}
);
}
},
{
startEvent: constants.EVENT_LOGIN_FAILED,
description: "",
dependencies: [
"app/comp/common/messages/MessagesCtrl",
"app/comp/user/login/LoginCtrl"
],
processDescription: function(event, messagesCtrl, loginCtrl) {
messagesCtrl.displayMessage('error', 'Login/password combination is invalid.');
loginCtrl.afterLoginFailed();
}
},
{
startEvent: constants.EVENT_LOGOUT,
description: "",
dependencies: [
"app/comp/main/MainCtrl",
"app/comp/user/login/LoginCtrl",
"app/comp/common/breadcrumbs/BreadcrumbsCtrl",
"app/comp/main/Configuration",
"app/comp/common/navigation/NavigationCtrl"
],
processDescription: function(event, mainCtrl, loginCtrl, breadcrumbsCtrl, conf, navigationCtrl) {
loginCtrl.logoutUser();
eventManager.sendEvent(constants.EVENT_AUTHENTICATION_DATA_CHANGED, { anonymousMode: true});
mainCtrl.clearContent();
breadcrumbsCtrl.clearPath();
breadcrumbsCtrl.set('Home');
conf.setProperty('loggedUser', null);
navigationCtrl.init();
}
}
];
return obj;
});