2016-03-27 16:32:29 +09:00
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-04-02 15:03:55 +02:00
|
|
|
|
import Router from '../router.js';
|
2016-03-27 16:32:29 +09:00
|
|
|
|
import { Dropdown } from 'react-bootstrap';
|
2016-03-29 17:16:51 +09:00
|
|
|
|
import { Button, Input } from 'react-bootstrap';
|
2016-03-27 16:32:29 +09:00
|
|
|
|
|
2016-04-02 21:05:02 +02:00
|
|
|
|
import { Accounts } from 'meteor/std:accounts-ui';
|
2016-03-29 17:16:51 +09:00
|
|
|
|
|
|
|
|
|
const AccountsMenu = () => {
|
2016-03-27 16:32:29 +09:00
|
|
|
|
|
|
|
|
|
({UserAvatar, UserName} = Telescope.components);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown id="accounts-dropdown" className="user-menu-dropdown">
|
|
|
|
|
<Dropdown.Toggle>
|
|
|
|
|
Log In
|
|
|
|
|
</Dropdown.Toggle>
|
|
|
|
|
<Dropdown.Menu>
|
2016-03-29 17:16:51 +09:00
|
|
|
|
<Accounts.ui.LoginForm />
|
2016-03-27 16:32:29 +09:00
|
|
|
|
</Dropdown.Menu>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
)
|
2016-04-02 15:03:55 +02:00
|
|
|
|
};
|
2016-03-27 16:32:29 +09:00
|
|
|
|
|
|
|
|
|
module.exports = AccountsMenu;
|
2016-03-29 17:16:51 +09:00
|
|
|
|
export default AccountsMenu;
|
|
|
|
|
|
|
|
|
|
// customize Accounts.ui
|
|
|
|
|
|
|
|
|
|
Accounts.ui.config({
|
|
|
|
|
passwordSignupFields: 'USERNAME_AND_EMAIL',
|
2016-04-02 17:03:03 +02:00
|
|
|
|
onSignedInHook: () => {},
|
|
|
|
|
onSignedOutHook: () => {},
|
2016-03-29 17:16:51 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
class AccountsButton extends Accounts.ui.Button {
|
|
|
|
|
render() {
|
2016-04-02 21:05:02 +02:00
|
|
|
|
const { label, href, type, disabled = false, className, onClick } = this.props;
|
|
|
|
|
if (type == 'link') {
|
|
|
|
|
return <Button bsStyle="default"
|
|
|
|
|
href="#"
|
|
|
|
|
className={ className }
|
|
|
|
|
onClick={ onClick }>{ label }</Button>;
|
|
|
|
|
}
|
|
|
|
|
return <Button bsStyle="primary"
|
|
|
|
|
type={ type }
|
|
|
|
|
className={ className }
|
|
|
|
|
onClick={ onClick }
|
|
|
|
|
disabled={ disabled }>{ label }</Button>;
|
2016-03-29 17:16:51 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AccountsField extends Accounts.ui.Field {
|
|
|
|
|
render() {
|
2016-04-02 21:05:02 +02:00
|
|
|
|
const { id, hint, label, type = 'text', onChange, className = "field", defaultValue = "" } = this.props;
|
|
|
|
|
const { mount = true } = this.state;
|
|
|
|
|
return mount ? (
|
|
|
|
|
<div className={ className }>
|
|
|
|
|
<Input id={ id } type={ type } onChange={ onChange } placeholder={ hint } defaultValue={ defaultValue } />
|
2016-03-29 17:16:51 +09:00
|
|
|
|
</div>
|
2016-04-02 21:05:02 +02:00
|
|
|
|
) : null;
|
2016-03-29 17:16:51 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-02 15:47:12 +02:00
|
|
|
|
class AccountsSocialButtons extends Accounts.ui.SocialButtons {
|
|
|
|
|
render () {
|
|
|
|
|
let { oauthServices = {}, className = "social_buttons" } = this.props;
|
|
|
|
|
return(
|
|
|
|
|
<div className={ className }>
|
|
|
|
|
{Object.keys(oauthServices)
|
|
|
|
|
.filter(service => oauthServices[service].disabled) // filter services registered but not enabled
|
|
|
|
|
.map((id, i) => <Accounts.ui.Button {...oauthServices[id]} key={i} />)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AccountsPasswordOrService extends Accounts.ui.PasswordOrService {
|
|
|
|
|
render () {
|
|
|
|
|
let {
|
|
|
|
|
oauthServices = {},
|
|
|
|
|
className,
|
|
|
|
|
style = {}
|
|
|
|
|
} = this.props;
|
|
|
|
|
let { hasPasswordService } = this.state;
|
|
|
|
|
let labels = Object.keys(oauthServices)
|
|
|
|
|
.filter(service => oauthServices[service].disabled) // filter services registered but not enabled
|
|
|
|
|
.map(service => oauthServices[service].label);
|
|
|
|
|
if (labels.length > 2) {
|
|
|
|
|
labels = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasPasswordService && labels.length > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div style={ style } className={ className }>
|
|
|
|
|
{ `${T9n.get('or use')} ${ labels.join(' / ') }` }
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 17:16:51 +09:00
|
|
|
|
Accounts.ui.Button = AccountsButton;
|
2016-04-02 21:05:02 +02:00
|
|
|
|
Accounts.ui.Field = AccountsField;
|
2016-04-02 15:47:12 +02:00
|
|
|
|
Accounts.ui.SocialButtons = AccountsSocialButtons;
|
2016-04-03 11:30:31 +09:00
|
|
|
|
Accounts.ui.PasswordOrService = AccountsPasswordOrService;
|