Skip to content

Commit

Permalink
Merge branch 'master' into RN_Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabieniec authored Jan 18, 2018
2 parents c8f0ac5 + be8db91 commit 652098f
Show file tree
Hide file tree
Showing 72 changed files with 2,215 additions and 1,127 deletions.
52 changes: 34 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# Changelog for AWS Amplify
<!--LATEST=0.1.30-->
<!--LATEST=0.1.35-->
<!--ENTRYINSERT-->

## 12/22/2017
## 01/16/2018
* aws-amplify - v0.1.35
* Improvements to Typescript developer experience. #155
* fix RN props #158
* delete ama #142
* aws-amplify-react-native - v0.1.23
* fix RN props #158

## 01/12/2018
* aws-amplify-react-native - v0.1.22
* bug fix: fix aws-sdk package
## 01/11/2018
* aws-amplify - v0.1.34
* bug fix: fix aws-sdk package
* bug fix: update main script

* aws-amplify - v0.1.30
## 01/09/2018

* aws-amplify - v0.1.32
* aws-amplify-react - v0.1.30
* aws-amplify-react-native - v0.1.20
* aws-ampliify-react-native - v0.1.21

* feature: Federated Authentication with Google and Facebook in React
* bugFix: Federated auth token fixes
* feature: Automatic S3 Analytics tracking with React components
* feature: Increase unit test coverage
* feature: Jest snapshot update
* feature: Update default auth theme
* feature: Export Signer interface for 3rd party HttpModules
* bugFix: aws-amplify-react-native: Update pinpoint region in React Native
* feature: Better support for guest (Unauthenticated) credentials
* bugFix: documentation: Fix broken link (to authentication)
* Enhancement: remove aws-sdk-mobile-analytics dependency from package.json

## 01/08/2018

Expand All @@ -33,10 +40,19 @@
* Bug fix: Doc syntax error fix
* Bug fix: Add charset on default header for API

## 01/09/2018
## 12/22/2017

* aws-amplify - v0.1.32
* aws-amplify - v0.1.30
* aws-amplify-react - v0.1.30
* aws-ampliify-react-native - v0.1.21
* aws-amplify-react-native - v0.1.20

* Enhancement: remove aws-sdk-mobile-analytics dependency from package.json
* feature: Federated Authentication with Google and Facebook in React
* bugFix: Federated auth token fixes
* feature: Automatic S3 Analytics tracking with React components
* feature: Increase unit test coverage
* feature: Jest snapshot update
* feature: Update default auth theme
* feature: Export Signer interface for 3rd party HttpModules
* bugFix: aws-amplify-react-native: Update pinpoint region in React Native
* feature: Better support for guest (Unauthenticated) credentials
* bugFix: documentation: Fix broken link (to authentication)
9 changes: 8 additions & 1 deletion media/authentication_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ Auth.confirmSignIn(user, code)
```js
import { Auth } from 'aws-amplify';

Auth.signUp(username, password, email, phone)
Auth.signUp({
username,
password,
email, // optional
phone, // optional
// other custom attributes if has been set in Cognito
// myAttr: ...
})
.then(data => console.log(data))
.catch(err => console.log(err));

Expand Down
42 changes: 29 additions & 13 deletions packages/aws-amplify-react-native/dist/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,46 @@ class AuthClass {

/**
* Sign up with username, password and other attrbutes like phone, email
* @param {String} username - The username to be signed up
* @param {String} password - The password of the user
* @param {String} email - The email of the user
* @param {String} phone_number - the phone number of the user
* @return {Promise} - A promise resolves callback data if success
* @param {String | object} attrs - The user attirbutes used for signin
* @param {String[]} restOfAttrs - for the backward compatability
* @return - A promise resolves callback data if success
*/
signUp(username, password, email, phone_number) {
signUp(attrs, ...restOfAttrs) {
if (!this.userPool) {
return Promise.reject('No userPool');
}

let username = null;
let password = null;
const attributes = [];
if (attrs && typeof attrs === 'string') {
username = attrs;
password = restOfAttrs ? restOfAttrs[0] : null;
const email = restOfAttrs ? restOfAttrs[1] : null;
const phone_number = restOfAttrs ? restOfAttrs[2] : null;
if (email) attributes.push({ Name: 'email', Value: email });
if (phone_number) attributes.push({ Name: 'phone_number', Value: phone_number });
} else if (attrs && typeof attrs === 'object') {
username = attrs['username'];
password = attrs['password'];
Object.keys(attrs).map(key => {
if (key === 'username' || key === 'password') return;
const ele = { Name: key, Value: attrs[key] };
attributes.push(ele);
});
} else {
return Promise.reject('The first parameter should either be non-null string or object');
}

if (!username) {
return Promise.reject('Username cannot be empty');
}
if (!password) {
return Promise.reject('Password cannot be empty');
}

const attributes = [];
if (email) {
attributes.push({ Name: 'email', Value: email });
}
if (phone_number) {
attributes.push({ Name: 'phone_number', Value: phone_number });
}
logger.debug('signUp attrs:');
logger.debug(attributes);

return new Promise((resolve, reject) => {
this.userPool.signUp(username, password, attributes, null, function (err, data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import VerifyContact from './VerifyContact';
import SignUp from './SignUp';
import ConfirmSignUp from './ConfirmSignUp';
import ForgotPassword from './ForgotPassword';
import RequireNewPassword from './RequireNewPassword';
import Greetings from './Greetings';

const logger = new Logger('Authenticator');
Expand Down Expand Up @@ -57,7 +58,7 @@ export default class Authenticator extends React.Component {
super(props);
this.state = {
authState: props.authState || 'signIn',
authDate: props.authData
authData: props.authData
};

this.handleStateChange = this.handleStateChange.bind(this);
Expand Down Expand Up @@ -106,7 +107,7 @@ export default class Authenticator extends React.Component {

const { hideDefault } = this.props;
const props_children = this.props.children || [];
const default_children = [React.createElement(SignIn, null), React.createElement(ConfirmSignIn, null), React.createElement(VerifyContact, null), React.createElement(SignUp, null), React.createElement(ConfirmSignUp, null), React.createElement(ForgotPassword, null), React.createElement(Greetings, null)];
const default_children = [React.createElement(SignIn, null), React.createElement(ConfirmSignIn, null), React.createElement(VerifyContact, null), React.createElement(SignUp, null), React.createElement(ConfirmSignUp, null), React.createElement(ForgotPassword, null), React.createElement(RequireNewPassword, null), React.createElement(Greetings, null)];
const children = (hideDefault ? [] : default_children).concat(props_children).map((child, index) => {
return React.cloneElement(child, {
key: 'auth_piece_' + index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class RequireNewPassword extends AuthPiece {
React.createElement(Button, {
title: I18n.get('Change Password'),
onPress: this.change,
disabled: !this.state.code
disabled: !this.state.password
})
),
React.createElement(Footer, { theme: theme, onStateChange: this.changeState }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export default class VerifyContact extends AuthPiece {
selectedValue: this.state.pickAttr,
onValueChange: (value, index) => this.setState({ pickAttr: value })
},
email ? React.createElement(Picker.Item, { label: 'Email', value: 'email' }) : null,
phone_number ? React.createElement(Picker.Item, { label: 'Phone Number', value: 'phone_number' }) : null
email ? React.createElement(Picker.Item, { label: I18n.get('Email'), value: 'email' }) : null,
phone_number ? React.createElement(Picker.Item, { label: I18n.get('Phone Number'), value: 'phone_number' }) : null
),
React.createElement(Button, {
title: I18n.get('Verify'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import ConfirmSignIn from './ConfirmSignIn';
import SignUp from './SignUp';
import ConfirmSignUp from './ConfirmSignUp';
import ForgotPassword from './ForgotPassword';
import RequireNewPassword from './RequireNewPassword';
import VerifyContact from './VerifyContact';
import Greetings from './Greetings';

const logger = new Logger('auth components');

export { Authenticator, AuthPiece, SignIn, ConfirmSignIn, SignUp, ConfirmSignUp, ForgotPassword, VerifyContact, Greetings };
export { Authenticator, AuthPiece, SignIn, ConfirmSignIn, SignUp, ConfirmSignUp, ForgotPassword, RequireNewPassword, VerifyContact, Greetings };

export function withAuthenticator(Comp, includeGreetings = false) {
class Wrapper extends React.Component {
Expand Down
12 changes: 6 additions & 6 deletions packages/aws-amplify-react-native/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/aws-amplify-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-amplify-react-native",
"version": "0.1.22",
"version": "0.1.23",
"description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.",
"main": "dist/index.js",
"scripts": {
Expand Down
46 changes: 35 additions & 11 deletions packages/aws-amplify-react-native/src/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,48 @@ class AuthClass {

/**
* Sign up with username, password and other attrbutes like phone, email
* @param {String} username - The username to be signed up
* @param {String} password - The password of the user
* @param {String} email - The email of the user
* @param {String} phone_number - the phone number of the user
* @return {Promise} - A promise resolves callback data if success
* @param {String | object} attrs - The user attirbutes used for signin
* @param {String[]} restOfAttrs - for the backward compatability
* @return - A promise resolves callback data if success
*/
signUp(username, password, email, phone_number) {
signUp(attrs, ...restOfAttrs) {
if (!this.userPool) { return Promise.reject('No userPool'); }
if (!username) { return Promise.reject('Username cannot be empty'); }
if (!password) { return Promise.reject('Password cannot be empty'); }

let username = null;
let password = null;
const attributes = [];
if (email) { attributes.push({Name: 'email', Value: email}); }
if (phone_number) { attributes.push({Name: 'phone_number', Value: phone_number}); }
if (attrs && typeof attrs === 'string') {
username = attrs;
password = restOfAttrs? restOfAttrs[0] : null;
const email = restOfAttrs? restOfAttrs[1] : null;
const phone_number = restOfAttrs? restOfAttrs[2] : null;
if (email) attributes.push({Name: 'email', Value: email});
if (phone_number) attributes.push({Name: 'phone_number', Value: phone_number});
} else if (attrs && typeof attrs === 'object') {
username = attrs['username'];
password = attrs['password'];
Object.keys(attrs).map(key => {
if (key === 'username' || key === 'password') return;
const ele = { Name: key, Value: attrs[key] };
attributes.push(ele);
});
} else {
return Promise.reject('The first parameter should either be non-null string or object');
}

if (!username) { return Promise.reject('Username cannot be empty'); }
if (!password) { return Promise.reject('Password cannot be empty'); }

logger.debug('signUp attrs:');
logger.debug(attributes);

return new Promise((resolve, reject) => {
this.userPool.signUp(username, password, attributes, null, function(err, data) {
if (err) { reject(err); } else { resolve(data); }
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import VerifyContact from './VerifyContact';
import SignUp from './SignUp';
import ConfirmSignUp from './ConfirmSignUp';
import ForgotPassword from './ForgotPassword';
import RequireNewPassword from './RequireNewPassword';
import Greetings from './Greetings';

const logger = new Logger('Authenticator');
Expand Down Expand Up @@ -59,7 +60,7 @@ export default class Authenticator extends React.Component {
super(props);
this.state = {
authState: props.authState || 'signIn',
authDate: props.authData
authData: props.authData
};

this.handleStateChange = this.handleStateChange.bind(this);
Expand Down Expand Up @@ -111,6 +112,7 @@ export default class Authenticator extends React.Component {
<SignUp/>,
<ConfirmSignUp/>,
<ForgotPassword/>,
<RequireNewPassword />,
<Greetings/>
];
const children = (hideDefault? [] : default_children)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class RequireNewPassword extends AuthPiece {
<Button
title={I18n.get('Change Password')}
onPress={this.change}
disabled={!this.state.code}
disabled={!this.state.password}
/>
</View>
<Footer theme={theme} onStateChange={this.changeState}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export default class VerifyContact extends AuthPiece {
selectedValue={this.state.pickAttr}
onValueChange={(value, index) => this.setState({pickAttr: value})}
>
{ email? <Picker.Item label="Email" value="email"/> : null }
{ phone_number? <Picker.Item label="Phone Number" value="phone_number"/> : null }
{ email? <Picker.Item label={I18n.get('Email')} value="email"/> : null }
{ phone_number? <Picker.Item label={I18n.get('Phone Number')} value="phone_number"/> : null }
</Picker>
<Button
title={I18n.get('Verify')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ConfirmSignIn from './ConfirmSignIn';
import SignUp from './SignUp';
import ConfirmSignUp from './ConfirmSignUp';
import ForgotPassword from './ForgotPassword';
import RequireNewPassword from './RequireNewPassword';
import VerifyContact from './VerifyContact';
import Greetings from './Greetings';

Expand All @@ -36,6 +37,7 @@ export {
SignUp,
ConfirmSignUp,
ForgotPassword,
RequireNewPassword,
VerifyContact,
Greetings
};
Expand Down
Loading

0 comments on commit 652098f

Please sign in to comment.