VALID_EMAIL_REGEX = `(?i)^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$`
)
+func UserConfirmed(c *gin.Context) *Error {
+ user, exists := c.Get("user")
+
+ if !exists {
+ return &Error{NotAuthorized, "not authorized", fmt.Errorf("no user key in context")}
+ }
+
+ if user.(db.User).Status != db.Confirmed {
+ return &Error{UserNotConfirmed, "user awaiting admin validation", fmt.Errorf("user '%v' not confirmed", user)}
+ }
+
+ return nil
+}
+
+func GetUser(c *gin.Context) db.User {
+ user, _ := c.Get("user")
+
+ return user.(db.User)
+}
+
func IsValidEmailAddress(email string) bool {
r := regexp.MustCompile(VALID_EMAIL_REGEX)
return SignResult{token}, nil
}
-func UserConfirmed(c *gin.Context) *Error {
- user, exists := c.Get("user")
-
- if !exists {
- return &Error{NotAuthorized, "not authorized", fmt.Errorf("no user key in context")}
- }
-
- if user.(db.User).Status != db.Confirmed {
- return &Error{UserNotConfirmed, "user awaiting admin validation", fmt.Errorf("user '%v' not confirmed", user)}
- }
-
- return nil
-}
-
-func GetUser(c *gin.Context) db.User {
- user, _ := c.Get("user")
-
- return user.(db.User)
-}
-
type ConfirmEmailQuery struct {
In struct {
Token string
return nil, nil
}
+
+type UserAccountQuery struct {
+ In struct {
+ User db.User
+ }
+ Out struct {
+ Email string `json:"email"`
+ }
+}
+
+func (q UserAccountQuery) ValidateParams() *Error {
+ return nil
+}
+
+func (q UserAccountQuery) Run() (interface{}, *Error) {
+ q.Out.Email = q.In.User.Email
+
+ return q.Out, nil
+}
import Api from './api.js';
import React from 'react';
+import classnames from 'classnames';
+
+class Panel extends React.Component {
+ render = () => {
+ if (this.props.component === null) {
+ return <div></div>;
+ }
+
+ var className = classnames('row', this.props.topClassName);
+
+ return (
+ <div className={className}>
+ <div className="box col-12">
+ <div className="row">
+ <div className="col-4">{this.props.title}</div>
+ </div>
+ <hr/>
+ {this.props.component}
+ </div>
+ </div>);
+ }
+}
+
+class AccountInformation extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {'email': null};
+ }
+
+ loadAccount = () => {
+ Api.Call('USER_ACCOUNT', {}, function(err, status, data) {
+ if (err) {
+ console.error(err, data);
+ return;
+ }
+
+ this.setState({'email': data.email});
+ }.bind(this));
+ }
+
+ componentDidMount = () => {
+ this.loadAccount();
+ }
+
+ render = () => {
+ var component = <p>Loading...</p>;
+ if (this.state.email !== null) {
+ component = <p>Email: {this.state.email}</p>;
+ }
+
+ return component;
+ }
+
+}
class PoloniexConfiguration extends React.Component {
constructor(props) {
super(props);
- this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'status': 'loading', 'editMode': false};
+ this.state = {'apiKey': '', 'apiSecret': '', 'status': 'loading', 'editMode': false};
}
checkCredentials = () => {
Api.Call('MARKET_TEST_CREDENTIALS', {'name': 'poloniex'}, function(err, status, data) {
- this.setState({'apiRequested': true});
if (err) {
console.error(err, data);
if (err.code === 'invalid_market_credentials') {
onEditClick = () => {
Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) {
- this.setState({'apiRequested': true, 'editMode': true});
+ this.setState({'editMode': true});
if (err) {
console.error(err, data);
return;
console.error('unknown status', this.state.status);
displayText = null;
}
- if (this.state.apiRequested === false) {
- return <div></div>;
- }
+
return (
- <div>
<PoloniexCredentialsForm onLoadCredentials={this.onLoadCredentials}
onCredentialsSubmit={this.handleCredentialsSubmit}
onCredentialsChange={this.handleCredentialsChange}
statusMessage={displayText}
editMode={this.state.editMode}
onEditClick={this.onEditClick}/>
- </div>
);
}
}
}
return (
- <div className="row api-credentials-form">
- <div className="offset-2 col-8 box">
- <span className="text-center">Poloniex credentials</span>
- <hr/>
- <div className="row config-status">
- <div className="col-12">
- <span><i className={iconName}></i>{this.props.statusMessage}</span>
- </div>
- </div>
- <div className="row">
- <div className="col-12">
- <form role="form" onSubmit={this.handleSubmit}>
- <label className="w-100">Key:
- <input className="form-control" type="text" placeholder="key" value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.props.editMode}/>
- </label>
- <label className="w-100">Secret:
- <input className="form-control" type="text" placeholder="secret" value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.props.editMode}/>
- </label>
- <input className="form-control submit" type={submitType} value="Save" />
- <button className="form-control submit" style={{display: buttonDisplay}} onSubmit={null} onClick={this.props.onEditClick} type="button">Show/Edit</button>
- </form>
- </div>
- </div>
+ <React.Fragment>
+ <div className="row config-status">
+ <div className="col-12">
+ <span><i className={iconName}></i>{this.props.statusMessage}</span>
</div>
</div>
+ <div className="row">
+ <div className="col-12">
+ <form role="form" onSubmit={this.handleSubmit}>
+ <label className="w-100">Key:
+ <input className="form-control" type="text" placeholder="key" value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.props.editMode}/>
+ </label>
+ <label className="w-100">Secret:
+ <input className="form-control" type="text" placeholder="secret" value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.props.editMode}/>
+ </label>
+ <input className="form-control submit" type={submitType} value="Save" />
+ <button className="form-control submit" style={{display: buttonDisplay}} onSubmit={null} onClick={this.props.onEditClick} type="button">Show/Edit</button>
+ </form>
+ </div>
+ </div>
+ </React.Fragment>
);
}
}
-export default PoloniexConfiguration;
+class UserAccount extends React.Component {
+ render = () => {
+ return (
+ <React.Fragment>
+ <Panel component={<AccountInformation/>} title="Account" />
+ <Panel component={<PoloniexConfiguration/>} title="Poloniex credentials" topClassName="api-credentials-form" />
+ </React.Fragment>
+ );
+ }
+}
+
+export default UserAccount;