Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CiscoGuestUser = Class.create();
- CiscoGuestUser.prototype = {
- _passwordChars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
- _ciscoAuthProfile: (function() {
- var profileRecord = new GlideRecord('sys_auth_profile_basic');
- var profileId = profileRecord.get('name', 'Cisco') ? profileId.sys_id + '' : 'b7171752db3a93c0197bb14ffe9619f3';
- return {
- type: 'basic',
- profileId: profileId
- };
- })(),
- initialize: function(/*GlideRecord*/ guestRecord) {
- if(guestRecord) {
- this.setFromRecord(guestRecord);
- }
- },
- setFromRecord: function(/*GlideRecord*/ guestRecord) {
- this._guestName = guestRecord.u_guest + '';
- this._guestCompanyName = guestRecord.u_company + '';
- this._ciscoUserName = this._generateUserName();
- this._ciscoUserPassword = this._generateRandomPassword();
- },
- _generateRandomPassword: function() {
- var randomPass = '';
- for(var i = 0; i < 8; i++) {
- randomPass += this._passwordChars.charAt(Math.floor(Math.random() * this._passwordChars.length));
- }
- return randomPass;
- },
- _generateUserName: function() {
- return ('HOM.' + this._guestName.trim().split(/\s+/).map(function(el, index) {
- if(index == 0)
- return el.split('')[0].toUpperCase();
- else if(index == 1)
- return '.' + el;
- else return '';
- }).join('') + '-' + this._guestCompanyName).split('').slice(0, 27).join('');
- },
- getGuestName: function() {
- return this._guestName;
- },
- getGuestCompany: function() {
- return this._guestCompanyName;
- },
- getCiscoUserName: function() {
- return this._ciscoUserName;
- },
- getCiscoUserPassword: function() {
- return this._ciscoUserPassword;
- },
- createUser: function() {
- var headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json'
- },
- createEndpoint = gs.getProperty('hoffmann.cisco.guest.create.endpoint') || 'https://demucsrnmpi01.corp.hoffmann-group.com/webacs/api/v3/op/guestUser',
- midServer = 'demucsrapmid01-test',
- httpMethod = 'post',
- httpTimeout = 60,
- async = true,
- reqBody = JSON.stringify({
- manageGuestUsersDTO: {
- applyGuestUserTo: 'CONTROLLER_LIST',
- controllerIds: {
- controllerId: [607674067]
- },
- description: 'test',
- disclaimer: 'test',
- //to-do change to take date from departure field and format it
- endTime: "2018-10-06T16:39:52.637Z",
- password: this.getCiscoUserPassword(),
- profile: 'HOG_GUEST',
- rebootController: false,
- saveConfigToFlash: true,
- userRole: 'default',
- username: this.getCiscoUserName()
- }
- });
- var req = new sn_ws.RESTMessageV2();
- req.setEndpoint(createEndpoint);
- req.setAuthenticationProfile(this._ciscoAuthProfile.type, this._ciscoAuthProfile.profileId);
- req.setHttpMethod(httpMethod);
- req.setHttpTimeout(httpTimeout);
- req.setMIDServer(midServer);
- for(var header in headers) {
- req.setRequestHeader(header, headers[header]);
- }
- req.setRequestBody(reqBody);
- var res = async == true ? req.executeAsync() : req.execute();
- RESTLogger.logOutbound(req, res, {
- midServer: midServer,
- httpMethod: httpMethod,
- httpTimeout: httpTimeout,
- async: async,
- authType: this._ciscoAuthProfile.type,
- profileId: this._ciscoAuthProfile.profileId
- });
- return !res.haveError();
- },
- type: 'CiscoGuestUser'
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement