Skip to content

Commit

Permalink
Fix change password. Closes #35
Browse files Browse the repository at this point in the history
Fix zeroes. Closes #31
Fix send yourself. Closes #29
Fix email case sensetive. Closes #28
  • Loading branch information
AlekNS committed Feb 12, 2018
1 parent 90a1779 commit 5b95ae0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class UserController {
(req, res, next) => {
commonFlowRequestMiddleware(Joi.object().keys({
oldPassword: Joi.string().required(),
newPassword: Joi.string().required().regex(passwordRegex)
newPassword: Joi.string().regex(passwordRegex).disallow(Joi.ref('oldPassword')).required()
}), req.body, res, next);
}
)
Expand Down
2 changes: 2 additions & 0 deletions src/services/app/dashboard.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class DashboardApplication {
* @param contractAddress
*/
getErc20TokenInfo(contractAddress: string): Promise<any> {
contractAddress = toEthChecksumAddress(contractAddress);

this.logger.debug('Request token info for', contractAddress);

return dashboardCache.run('erc20info' + contractAddress, async() => {
Expand Down
6 changes: 5 additions & 1 deletion src/services/app/transaction.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,15 @@ export class TransactionApplication {
throw new IncorrectMnemonic('Incorrect payment password, invalid address');
}

if (transData.to.toLowerCase() === account.address.toLowerCase()) {
throw new NotCorrectTransactionRequest('Senseless operation, to send to yourself');
}

if (transData.type === ERC20_TRANSFER && !transData.contractAddress) {
throw new NotCorrectTransactionRequest('Empty token address');
}

let amount = '' + transData.amount;
let amount = ('' + transData.amount).replace(/0+$/, ''); // remove last zeroes
if (transData.type === ERC20_TRANSFER) {
const token = user.wallets[0].getTokenByContractAddress(transData.contractAddress);
amount = fromUnitValueToWei(amount, token && token.decimals || 0);
Expand Down
6 changes: 6 additions & 0 deletions src/services/app/user/user.account.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export class UserAccountApplication {
* @return promise
*/
async create(userData: InputUserData): Promise<CreatedUserData> {
// it better to use collate in mongo index
userData.email = userData.email.toLowerCase();

if (userData.password === userData.paymentPassword) {
throw new InvalidPassword('Login and payment passwords are matched');
}
Expand Down Expand Up @@ -261,6 +264,9 @@ export class UserAccountApplication {
* @return promise
*/
async initiateLogin(loginData: InitiateLoginInput, ip: string): Promise<InitiateLoginResult> {
// it better to use collate in mongo index
loginData.email = loginData.email.toLowerCase();

const user = await getConnection().getMongoRepository(User).findOne({
email: loginData.email
});
Expand Down
9 changes: 9 additions & 0 deletions src/services/app/user/user.password.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class UserPasswordApplication {
* @param params
*/
async initiateResetPassword(params: ResetPasswordInput): Promise<BaseInitiateResult> {
// it better to use collate in mongo index
params.email = params.email.toLowerCase();

const user = await getConnection().getMongoRepository(User).findOne({
email: params.email
});
Expand Down Expand Up @@ -172,6 +175,9 @@ export class UserPasswordApplication {
* @param params
*/
async verifyResetPassword(params: ResetPasswordInput): Promise<any> {
// it better to use collate in mongo index
params.email = params.email.toLowerCase();

const user = await getConnection().getMongoRepository(User).findOne({
email: params.email
});
Expand Down Expand Up @@ -199,6 +205,9 @@ export class UserPasswordApplication {
* @param params
*/
async resetPasswordEnter(params: { email: string, password: string, resetId: string }) {
// it better to use collate in mongo index
params.email = params.email.toLowerCase();

const user = await getConnection().getMongoRepository(User).findOne({
email: params.email
});
Expand Down

0 comments on commit 5b95ae0

Please sign in to comment.