(function () { 'use strict'; var serviceId = 'userSettingsDataContext'; angular.module('user').factory(serviceId, ['$window', 'appDataContext', 'userConfig', 'config', dataContext]); function dataContext($window, appDataContext, userConfig, appConfig) { var service = {}; /** * Check if the provided email is available */ service.isEmailAvailable = function (email) { return appDataContext.get(userConfig.userProfileServiceUrl + 'emailavailable?email=' + email); } /** * Check if the provided username is available */ service.isUsernameAvailable = function (username) { return appDataContext.get(appConfig.myusersUrl + 'api/account/usernameavailable?username=' + username); } /** * Change the users password */ service.changePassword = function (model) { return appDataContext.post(appConfig.myusersUrl + 'api/account/changepassword', model); } /** * Resend an email verification code for this user */ service.resendEmailVerification = function (email, brandOrganisationId) { var data = { emailToVerify: email, applicationId: appConfig.applicationId, appCode: appConfig.appCode, organisationBrandingId: brandOrganisationId, isAdditionalEmail: true, applicationTemplateUrl: appConfig.siteUrl } return sendEmail(data); } /** * Send an activation code for this user */ service.sendActivation = function (email, isSetPassword) { var data = { emailToVerify: email, applicationId: appConfig.applicationId, appCode: appConfig.appCode, isSetPassword: isSetPassword, isAdditionalEmail: false, applicationTemplateUrl: appConfig.siteUrl }; return sendEmail(data); } /** * Get the notification schedule for this user */ service.getNotificationSchedule = function () { return appDataContext.get(appConfig.apigatewayUrl + 'notifications/api/schedule/user/appcode/' + appConfig.appCode); } /** * Create the notification schedule for this user */ service.createNotificationSchedule = function (schedule) { return appDataContext.post(appConfig.apigatewayUrl + 'notifications/api/schedule/', schedule); } /** * Update the notification schedule for this user */ service.updateNotificationSchedule = function (schedule) { return appDataContext.put(appConfig.apigatewayUrl + 'notifications/api/schedule/' + schedule.id, schedule); } service.getStuffExportResult = function () { return appDataContext.get(appConfig.apigatewayUrl + 'myshowcaseexport/export'); } service.triggerStuffExport = function () { return appDataContext.post(appConfig.apigatewayUrl + 'myshowcaseexport/export/trigger'); } service.downloadStuffExport = function () { return appDataContext.getAsFile(appConfig.apigatewayUrl + 'myshowcaseexport/export/download'); } service.getCurrentStatusByTenant = function (tenantId, userId) { return appDataContext.get(appConfig.myusersUrl + 'api/myusers/' + tenantId + '/status/' + userId); } return service; /** * Send an email verification code for this user with * the provided data */ function sendEmail(data) { return appDataContext.post(myusersUrl + 'api/emailverifications' + '?host=' + $window.location.host, data); } } })();