-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
144 additions
and
181 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> Registration</h1> | ||
</div> | ||
<div> User:</div> | ||
<div> | ||
| ||
{<Input style={{ width: '20%' }} id='login' />} | ||
</div> | ||
<div> </div> | ||
<div> Password:</div> | ||
<div> | ||
| ||
{<Input style={{ width: '20%' }} type='password' maxLength='15' id='password' />} | ||
</div> | ||
<div> </div> | ||
<div className='form-operations'> | ||
| ||
<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> | ||
)); |