Skip to content

Commit

Permalink
Высылаю Лаб3
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevma committed Jul 3, 2019
1 parent 3853904 commit afdbcc8
Showing 1 changed file with 144 additions and 0 deletions.
144 changes: 144 additions & 0 deletions src/RegisterForm.stories.js
Original file line number Diff line number Diff line change
@@ -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 (
<Form name='form1'>
<div>
<h1>&nbsp;&nbsp;Registration</h1>
</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User:</div>
<div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{<Input style={{ width: '20%' }} id='login' />}
</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password:</div>
<div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{<Input style={{ width: '20%' }} type='password' maxLength='15' id='password' />}
</div>
<div>&nbsp;</div>
<div className='form-operations'>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<Button onClick={this.setRegistration} type='primary' htmlType='submit'>
Register
</Button>
<Button style={{ marginLeft: 8 }} onClick={this.handleReset} type='primary' htmlType='submit'>
Clear
</Button>
</div>
</Form>
);
}
}

const WrappedAdvancedSearchForm = Form.create({ name: 'normal_login' })(AdvancedSearchForm);

storiesOf('Register Form', module).add('Action', () => (
<WrappedAdvancedSearchForm>Register Form</WrappedAdvancedSearchForm>
));

0 comments on commit afdbcc8

Please sign in to comment.