diff --git a/src/RegisterForm.stories.js b/src/RegisterForm.stories.js new file mode 100644 index 000000000..ec19bcf93 --- /dev/null +++ b/src/RegisterForm.stories.js @@ -0,0 +1,144 @@ +import { storiesOf } from '@storybook/react'; +import React from 'react'; + +import { Form, Button, Checkbox, Input } from 'antd'; + +//cas.javascript.file = /js/cas.js +//import {cas} from frontend.properties; +//import { cas } from "org.jasig.cas:cas-server-support-rest:${project.'cas.version'}"; + +class AdvancedSearchForm extends React.Component { + setRegistration = async () => { + let login = document.getElementById('login').value; + let password = document.getElementById('password').value; + + if (login == '') alert('Введите логин!!!'); + else if (password == '') alert('Введите пароль!!!'); + else if (login.trim() == '') alert('Логин не должен содержать одни пробелы!!!'); + else if (password.trim() == '') alert('Пароль не должен содержать одни пробелы!!!'); + + console.log(login); + var encryptedlogin = this.Encryptor(login); + console.log(encryptedlogin); + + console.log(password); + var encryptedpassw = this.Encryptor(password); + console.log(encryptedpassw); + + //let getusers = await this.getUser(encryptedlogin, encryptedpassw).then((r) => r.json()); + //console.log(getusers); + + let addusers = await this.addUser(encryptedlogin, encryptedpassw).then((r) => r.json()); + console.log(addusers); + + alert('Регистрация успешно завершена!'); + + this.handleReset(); + }; + + getUser = (username, password) => { + let shit = 'https://cors-anywhere.herokuapp.com/'; + let url = 'http://82.202.226.30:8080'; + let prefix = '/master/api/1/users'; + + var adminname = 'master'; + var adminpassword = 'commander'; + var headers = new Headers(); + headers.append('Authorization', 'Basic ' + btoa(adminname + ':' + adminpassword)); + headers.append('Content-Type', 'application/json'); + + let webData = fetch(shit + url.concat(prefix), { + method: 'GET', + headers: headers, + body: JSON.stringify(data), + }); + + return webData; + }; + + addUser = (username, password) => { + let shit = 'https://cors-anywhere.herokuapp.com/'; + let url = 'http://82.202.226.30:8080'; + let prefix = '/master/api/1/users/create'; + + var adminname = 'master'; + var adminpassword = 'commander'; + var headers = new Headers(); + headers.append('Authorization', 'Basic ' + btoa(adminname + ':' + adminpassword)); + headers.append('Content-Type', 'application/json'); + + var data = { + 'Subject.UPVSIdentityID': username, + 'Subject.FormattedName': username, + 'Actor.UPVSIdentityID': password, + 'Actor.FormattedName': password, + 'SPR.Roles': 'simple-user', + }; + + let webData = fetch(shit + url.concat(prefix), { + method: 'POST', + headers: headers, + body: JSON.stringify(data), + }); + + return webData; + }; + + Encryptor = (text) => { + const crypto = require('crypto'); + const cipher = crypto.createCipher('aes192', text); + + var encrypted = ''; + cipher.on('readable', () => { + var data = cipher.read(); + if (data) encrypted += data.toString('hex'); + }); + + cipher.end(); + return encrypted; + }; + + handleReset = () => { + var inputs = document.querySelectorAll('Input'); + for (var i = 0; i < inputs.length; i++) { + inputs[i].value = ''; + } + }; + + render() { + return ( +
+
+

  Registration

+
+
     User:
+
+        + {} +
+
 
+
     Password:
+
+        + {} +
+
 
+
+        + + +
+
+ ); + } +} + +const WrappedAdvancedSearchForm = Form.create({ name: 'normal_login' })(AdvancedSearchForm); + +storiesOf('Register Form', module).add('Action', () => ( + Register Form +));