mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-22 21:35:05 +02:00
Ivan - Backend - Fixes to make frontend work with API [skip ci]
This commit is contained in:
parent
c787be375d
commit
06ad75b688
@ -17,7 +17,7 @@ gulp.task('server', function() {
|
||||
server.use(express.static(config.buildDir));
|
||||
|
||||
// Proxy php server api
|
||||
server.use('/api', proxy('http://localhost:8080/', {
|
||||
server.use('/api', proxy('http://localhost:8080', {
|
||||
forwardPath: function(req, res) {
|
||||
return require('url').parse(req.url).path;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export default {
|
||||
path: '/user/login',
|
||||
data: loginData
|
||||
}).then((result) => {
|
||||
store.dispatch(this.getUserData(result.data.userId));
|
||||
store.dispatch(this.getUserData(result.data.userId, result.data.token));
|
||||
|
||||
return result;
|
||||
})
|
||||
@ -32,7 +32,7 @@ export default {
|
||||
isAutomatic: true
|
||||
}
|
||||
}).then((result) => {
|
||||
store.dispatch(this.getUserData(result.data.userId));
|
||||
store.dispatch(this.getUserData(result.data.userId, result.data.token));
|
||||
|
||||
return result;
|
||||
})
|
||||
@ -49,14 +49,21 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
getUserData(userId) {
|
||||
getUserData(userId, token) {
|
||||
let data = {};
|
||||
|
||||
if (userId && token) {
|
||||
data = {
|
||||
csrf_userid: userId,
|
||||
csrf_token: token
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'USER_DATA',
|
||||
payload: API.call({
|
||||
path: '/user/get',
|
||||
data: {
|
||||
userId: userId
|
||||
}
|
||||
data: data
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -14,13 +14,13 @@ class Captcha extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
return (this.props.sitekey) ? (
|
||||
<ReCAPTCHA sitekey={this.props.sitekey} ref="reCaptcha" onChange={(value) => {this.setState({value})}} tabIndex="0" />
|
||||
);
|
||||
) : <div></div>;
|
||||
}
|
||||
|
||||
getValue() {
|
||||
return this.state.value;
|
||||
return (this.props.sitekey) ? this.state.value : 'valid';
|
||||
}
|
||||
|
||||
focus() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import ReCAPTCHA from 'react-google-recaptcha';
|
||||
import { browserHistory } from 'react-router';
|
||||
|
||||
@ -90,7 +91,9 @@ class CreateTicketForm extends React.Component {
|
||||
|
||||
API.call({
|
||||
path: '/ticket/create',
|
||||
data: formState
|
||||
data: _.extend({}, formState, {
|
||||
departmentId: formState.departmentId + 1
|
||||
})
|
||||
}).then(this.onTicketSuccess.bind(this)).catch(this.onTicketFail.bind(this));
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class TicketAction extends React.Component {
|
||||
<span className="ticket-action__comment-author-type">({i18n((config.author.staff) ? 'STAFF' : 'CUSTOMER')})</span>
|
||||
</div>
|
||||
<div className="ticket-action__comment-date">{config.date}</div>
|
||||
<div className="ticket-action__comment-content">{config.content}</div>
|
||||
<div className="ticket-action__comment-content" dangerouslySetInnerHTML={{__html: config.content}}></div>
|
||||
{this.renderFileRow(config.file)}
|
||||
</div>
|
||||
);
|
||||
|
@ -1,6 +1,11 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
import i18n from 'lib-app/i18n';
|
||||
import API from 'lib-app/api-call';
|
||||
import store from 'app/store';
|
||||
import SessionActions from 'actions/session-actions';
|
||||
|
||||
import i18n from 'lib-app/i18n';
|
||||
import TicketAction from 'app/main/dashboard/dashboard-ticket/ticket-action';
|
||||
import Form from 'core-components/form';
|
||||
import FormField from 'core-components/form-field';
|
||||
@ -19,6 +24,15 @@ class TicketViewer extends React.Component {
|
||||
}
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
loading: false
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="ticket-viewer">
|
||||
@ -45,7 +59,7 @@ class TicketViewer extends React.Component {
|
||||
<div className="ticket-viewer__response">
|
||||
<div className="ticket-viewer__response-title row">{i18n('RESPOND')}</div>
|
||||
<div className="ticket-viewer__response-field row">
|
||||
<Form>
|
||||
<Form onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}>
|
||||
<FormField name="content" validation="TEXT_AREA" required field="textarea" />
|
||||
<SubmitButton>{i18n('RESPOND_TICKET')}</SubmitButton>
|
||||
</Form>
|
||||
@ -60,6 +74,33 @@ class TicketViewer extends React.Component {
|
||||
<TicketAction type="comment" config={comment} key={index} />
|
||||
);
|
||||
}
|
||||
|
||||
onSubmit(formState) {
|
||||
this.setState({
|
||||
loading: true
|
||||
});
|
||||
|
||||
API.call({
|
||||
path: '/ticket/comment',
|
||||
data: _.extend({
|
||||
ticketNumber: this.props.ticket.ticketNumber
|
||||
}, formState)
|
||||
}).then(this.onCommentSuccess.bind(this), this.onCommentFail.bind(this));
|
||||
}
|
||||
|
||||
onCommentSuccess() {
|
||||
this.setState({
|
||||
loading: false
|
||||
});
|
||||
|
||||
store.dispatch(SessionActions.getUserData());
|
||||
}
|
||||
|
||||
onCommentFail() {
|
||||
this.setState({
|
||||
loading: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default TicketViewer;
|
@ -55,7 +55,7 @@ class MainLayoutHeader extends React.Component {
|
||||
return {
|
||||
className: 'main-layout-header__languages',
|
||||
items: this.getLanguageList(),
|
||||
selectedIndex: Object.keys(codeLanguages).map((key) => codeLanguages[key]).indexOf(this.props.config.language),
|
||||
selectedIndex: Object.keys(codeLanguages).map((key) => codeLanguages[key]).indexOf(this.getPropLanguage()),
|
||||
onChange: this.changeLanguage.bind(this)
|
||||
};
|
||||
}
|
||||
@ -69,10 +69,24 @@ class MainLayoutHeader extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
changeLanguage(event) {
|
||||
let language = Object.keys(codeLanguages)[event.index];
|
||||
getPropLanguage() {
|
||||
let language = this.props.config.language;
|
||||
|
||||
this.props.dispatch(ConfigActions.changeLanguage(codeLanguages[language]));
|
||||
if (language === 'en') {
|
||||
language = 'us';
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
changeLanguage(event) {
|
||||
let language = codeLanguages[Object.keys(codeLanguages)[event.index]];
|
||||
|
||||
if (language === 'us') {
|
||||
language = 'en';
|
||||
}
|
||||
|
||||
this.props.dispatch(ConfigActions.changeLanguage(language));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ class MainRecoverPasswordPage extends React.Component {
|
||||
<Widget title={i18n('RECOVER_PASSWORD')} className="col-md-4 col-md-offset-4">
|
||||
<Form className="recover-password__form" onSubmit={this.onRecoverPasswordSubmit.bind(this)} loading={this.state.loading}>
|
||||
<div className="recover-password__inputs">
|
||||
<FormField placeholder={i18n('NEW_PASSWORD')} name="password" className="recover-password__input" validation="PASSWORD" password required/>
|
||||
<FormField placeholder={i18n('REPEAT_NEW_PASSWORD')} name="password-repeat" className="recover-password__input" validation="REPEAT_PASSWORD" password required/>
|
||||
<FormField placeholder={i18n('NEW_PASSWORD')} name="password" className="recover-password__input" validation="PASSWORD" fieldProps={{password: true}} required/>
|
||||
<FormField placeholder={i18n('REPEAT_NEW_PASSWORD')} name="password-repeat" className="recover-password__input" validation="REPEAT_PASSWORD" fieldProps={{password: true}} required/>
|
||||
</div>
|
||||
<div className="recover-password__submit-button">
|
||||
<SubmitButton type="primary">{i18n('SUBMIT')}</SubmitButton>
|
||||
|
@ -4,6 +4,7 @@ import _ from 'lodash';
|
||||
|
||||
import i18n from 'lib-app/i18n';
|
||||
import API from 'lib-app/api-call';
|
||||
import SessionStore from 'lib-app/session-store';
|
||||
|
||||
import Captcha from 'app/main/captcha';
|
||||
import SubmitButton from 'core-components/submit-button';
|
||||
|
@ -7,7 +7,7 @@ import turkishLanguage from 'data/languages/en';
|
||||
import indianLanguage from 'data/languages/en';
|
||||
|
||||
const languages = {
|
||||
'us': englishLanguage,
|
||||
'en': englishLanguage,
|
||||
'es': spanishLanguage,
|
||||
'de': germanLanguage,
|
||||
'fr': frenchLanguage,
|
||||
|
@ -5,7 +5,10 @@ const SessionStore = require('lib-app/session-store');
|
||||
const root = 'http://localhost:3000/api';
|
||||
|
||||
function processData (data) {
|
||||
return _.extend(SessionStore.getSessionData(), data);
|
||||
return _.extend({
|
||||
csrf_token: SessionStore.getSessionData().token,
|
||||
csrf_userid: SessionStore.getSessionData().userId
|
||||
}, data);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -2,6 +2,7 @@
|
||||
include 'user/login.php';
|
||||
include 'user/signup.php';
|
||||
include 'user/logout.php';
|
||||
include 'user/check-session.php';
|
||||
include 'user/recover-password.php';
|
||||
include 'user/send-recover-password.php';
|
||||
include 'user/edit-password.php';
|
||||
@ -14,6 +15,7 @@ $userControllers->setGroupPath('/user');
|
||||
$userControllers->addController(new LoginController);
|
||||
$userControllers->addController(new SignUpController);
|
||||
$userControllers->addController(new LogoutController);
|
||||
$userControllers->addController(new CheckSessionController);
|
||||
$userControllers->addController(new SendRecoverPasswordController);
|
||||
$userControllers->addController(new RecoverPasswordController);
|
||||
$userControllers->addController(new EditPassword);
|
||||
|
@ -37,18 +37,21 @@ class SignUpController extends Controller {
|
||||
public function handler() {
|
||||
$this->storeRequestData();
|
||||
|
||||
try {
|
||||
$userId = $this->createNewUserAndRetrieveId();
|
||||
$this->sendRegistrationMail();
|
||||
$existentUser = User::getUser($this->userEmail, 'email');
|
||||
|
||||
Response::respondSuccess([
|
||||
'userId' => $userId,
|
||||
'userEmail' => $this->userEmail
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Response::respondError($e->getMessage());
|
||||
if (!$existentUser->isNull()) {
|
||||
Response::respondError(ERRORS::USER_EXISTS);
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $this->createNewUserAndRetrieveId();
|
||||
$this->sendRegistrationMail();
|
||||
|
||||
Response::respondSuccess([
|
||||
'userId' => $userId,
|
||||
'userEmail' => $this->userEmail
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function storeRequestData() {
|
||||
|
@ -2,6 +2,7 @@
|
||||
class ERRORS {
|
||||
const INVALID_CREDENTIALS = 'User or password is not defined';
|
||||
const SESSION_EXISTS = 'User is already logged in';
|
||||
const USER_EXISTS = 'Email already exists';
|
||||
const NO_PERMISSION = 'You have no permission to access';
|
||||
const INVALID_TITLE = 'Invalid title';
|
||||
const INVALID_CONTENT = 'Invalid content';
|
||||
|
Loading…
x
Reference in New Issue
Block a user