Skip to content

Commit

Permalink
Merge pull request #129 from alphamanuscript/master
Browse files Browse the repository at this point in the history
v0.2.2
  • Loading branch information
habbes authored Sep 7, 2020
2 parents cffcb72 + 4c62e3c commit 31dfd7d
Showing 10 changed files with 154 additions and 140 deletions.
13 changes: 4 additions & 9 deletions server/src/core/user/tests/validator.test.ts
Original file line number Diff line number Diff line change
@@ -18,16 +18,11 @@ describe('validatesCreate', () => {
testValidationFails(validators.validatesCreate, [
{ phone: '25472929109', password: 'dsksjjn,' },
{ phone: '25472929109', password: 'dsksjjn,', name: ''},
{ phone: '+254729291091', password: 'dsks12jnDM4' },
{ phone: '2548292910919', password: 'dsks12jnDM4SEZLZSS' },
{ phone: '254738103012', password: 'f' },
{ phone: '254738103012', password: 'wiedna102Ldnffrfldm' },
{ phone: '', password: 'wiedna102Ldnffrfldm' },
{ phone: '254738103012', password: '' },
{ password: 'wiedna102Ldnffrfldm' },
{ phone: '254738103012' },
{ phone: '254738103012', password: 1 },
{ phone: '254729291091', password: 'dsks12jnDM4SEZLZSS', googleIdToken: 'dsks12jnDM4SEZLZSS' },
{ phone: '254729291091', password: '', googleIdToken: 'dsks12jnDM4SEZLZSS' },
{ phone: '254729291091', password: 'dsks12jnDM4SEZLZSS', googleIdToken: '' },
{ phone: '', googleIdToken: 'dsks12jnDM4SEZLZSS' },
@@ -41,20 +36,20 @@ describe('validatesLogin', () => {
it('should not throw error if inputs are valid', () => {
testValidationSucceeds(validators.validatesLogin, [
{ phone: '254729291091', password: 'dsksjjn,' },
{ phone: '254738103012', password: 'f' },
{ phone: '254729291091', password: 'dsks12jnDM4' },
{ phone: '254729291091', password: 'dsks12jnDM4SEZLZSS' },
{ phone: '254729291091', googleIdToken: 'dsks12jnDM4SEZLZSS' },
{ phone: '254829291091', password: 'dsks12jnDM4SEZLZSS' },
{ phone: '254129291091', password: 'dsks12jnDM4SEZLZSS' },
{ phone: '254738103012', password: 'wiedna102Ldnffrfldm' },
{ googleIdToken: 'dsks12jnDM4SEZLZSS' }
]);
});
it('should throw error if inputs are not valid', () => {
testValidationFails(validators.validatesLogin, [
{ phone: '25472929109', password: 'dsksjjn,' },
{ phone: '+254729291091', password: 'dsks12jnDM4' },
{ phone: '2548292910916', password: 'dsks12jnDM4SEZLZSS' },
{ phone: '254738103012', password: 'f' },
{ phone: '254738103012', password: 'wiedna102Ldnffrfldm' },
{ phone: '254729291091', password: 'dsks12jnDM4SEZLZSS', googleIdToken: 'dsks12jnDM4SEZLZSS' },
{ phone: '', password: '', googleIdToken: 'dsks12jnDM4SEZLZSS' },
{ phone: '254729291091', password: 'dsks12jnDM4SEZLZSS', googleIdToken: '' },
{ phone: '', googleIdToken: 'dsks12jnDM4SEZLZSS' },
3 changes: 1 addition & 2 deletions server/src/core/util/validation-util.ts
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ export const validateId = makeValidatorFromJoiSchema(idValidationSchema);

export const phoneValidationSchema = joi.string()
.required()
.pattern(/^254\d{9}$/) // Starts with 254 and ends with 8 digits
.pattern(/^254\d{9}$/) // Starts with 254 and ends with 9 digits
.messages({
'any.required': 'Phone is required',
'string.base': 'Invalid type, phone must be a string',
@@ -32,7 +32,6 @@ export const phoneValidationSchema = joi.string()

export const passwordValidationSchema = joi.string()
.required()
.pattern(/^.{8,18}$/)
.messages({
'any.required': 'Password is required',
'string.base': 'Invalid type, password must be a string',
12 changes: 6 additions & 6 deletions server/yarn.lock
Original file line number Diff line number Diff line change
@@ -1146,9 +1146,9 @@ bignumber.js@^7.0.0:
integrity sha512-S4XzBk5sMB+Rcb/LNcpzXr57VRTxgAvaAEDAl1AwRx27j00hT84O6OkteE7u8UB3NuaaygCRrEpqox4uDOrbdQ==

bl@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-2.2.0.tgz#e1a574cdf528e4053019bb800b041c0ac88da493"
integrity sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==
version "2.2.1"
resolved "https://registry.yarnpkg.com/bl/-/bl-2.2.1.tgz#8c11a7b730655c5d56898cdc871224f40fd901d5"
integrity sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==
dependencies:
readable-stream "^2.3.5"
safe-buffer "^5.1.1"
@@ -4320,9 +4320,9 @@ [email protected], safe-buffer@~5.1.0, safe-buffer@~5.1.1:
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==

safe-regex@^1.1.0:
version "1.1.0"
18 changes: 9 additions & 9 deletions webapp/public/index.html
Original file line number Diff line number Diff line change
@@ -16,15 +16,15 @@
<!-- built files will be auto injected -->
<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/5d09f17f53d10a56bd7acc17/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/5f53c4bf4704467e89ec72ec/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
</body>
44 changes: 22 additions & 22 deletions webapp/src/components/donate-modal.vue
Original file line number Diff line number Diff line change
@@ -20,14 +20,14 @@
<b-form-input
v-model="donationInputs.amount"
type="number"
:state="validationResults[1]"
:state="validationResults.amount"
class="custom-dialog-form-input"
placeholder="Enter amount (Kshs)"
id="amount"
:value="donationInputs.amount"
/>
<b-form-invalid-feedback class="text-center">
{{ validationMessages[1] }}
{{ validationMessages.amount }}
</b-form-invalid-feedback>
<div class="text-center">
<span class="small">A transaction fee may be charged by the provider</span>
@@ -42,8 +42,8 @@

<script>
import { mapActions, mapState } from 'vuex';
import { validateObj } from '../views/util';
import ModalHeader from '../ui-components/modal-header';
import { validateNamedRules, validationRules, validationMessages } from '../views/util';
export default {
name: 'login-modal',
@@ -54,59 +54,59 @@ export default {
phone: '',
amount: 1000
},
validationMessages: [
'Invalid phone number. Must start with 7 and be 9 digit long',
'Insufficient amount. Donations must be at least of the amount 100',
],
validationRules: [
{ test: (donationInputs) => donationInputs.phone[0] === '7' && /^(?=.*\d)(?=.{9,9}$)/.test(donationInputs.phone) },
{ test: (donationInputs) => donationInputs.amount >= 100 },
],
validationResults: [null, null],
validationMessages: {
phone: validationMessages.phone,
amount: validationMessages.amount
},
validationRules: {
phone: validationRules.phone,
amount: validationRules.amount
},
validationResults: { phone: null, amount: null }
}
},
computed: {
...mapState(['user', 'message'])
},
methods: {
...mapActions(['donate']),
validateObj,
validateNamedRules,
showDonateDialog() {
this.donationInputs = {
phone: '',
amount: 1000
},
this.validationResults = [null, null];
this.validationResults = { phone: null, amount: null };
this.$bvModal.show('sign-up');
},
hideDialog() {
this.donationInputs = {
phone: '',
amount: 1000
},
this.validationResults = [null, null];
this.validationResults = { phone: null, amount: null };
},
setModalData() {
if (this.user) {
this.donationInputs.phone = this.user.phone.substring(3);
}
},
async submitDonation() {
this.validationMessages = [
'Invalid phone number. Must start with 7 and be 9 digit long',
'Insufficient amount. Donations must be at least of the amount 100',
];
this.validationMessages = {
phone: validationMessages.phone,
amount: validationMessages.amount
}
this.donationInputs.amount = Number(this.donationInputs.amount);
this.validationResults = this.validateObj(this.donationInputs, this.validationRules);
this.validationResults = this.validateNamedRules(this.donationInputs, this.validationRules);
if (!this.validationResults.includes(false)) {
if (!Object.values(this.validationResults).includes(false)) {
await this.donate({ amount: this.donationInputs.amount });
if (this.message.type !== 'error') {
this.donationInputs = {
phone: '',
amount: 1000
},
this.validationResults = [null, null];
this.validationResults = { phone: null, amount: null };
this.$bvModal.hide('donate');
this.$bvModal.show('confirm-donation');
}
44 changes: 22 additions & 22 deletions webapp/src/components/google-sign-up-modal.vue
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
</b-form-invalid-feedback>
</b-input-group>
<b-form-text v-show="showPhoneHelper" class="text-center">
Start with 7, for example 712345678
For example 712345678
</b-form-text>
</b-form-group>
<div class="text-center">
@@ -57,7 +57,7 @@

<script>
import { mapActions, mapState } from 'vuex';
import { validateObj } from '../views/util';
import { validateNamedRules, validationRules, validationMessages } from '../views/util';
export default {
name: 'google-sign-up-modal',
props: {
@@ -75,13 +75,13 @@ export default {
role: 'donor'
},
signUpValidationMessages: [
'Invalid Phone number. Must start with 7 and be 9 digits long'
],
signUpValidationRules: [
{ test: (creds) => creds.phone[0] === '7' && /^(?=.*\d)(?=.{9,9}$)/.test(creds.phone) }
],
signUpValidationResults: [null],
signUpValidationMessages: {
phone: validationMessages.phone
},
signUpValidationRules: {
phone: validationRules.phone,
},
signUpValidationResults: { phone: null },
helper: {
phone: false,
}
@@ -93,12 +93,12 @@ export default {
return require(`@/assets/Social Relief Logo_1.svg`);
},
showPhoneHelper () {
return this.signUpValidationResults[0] == null && this.helper.phone;
return this.signUpValidationResults.phone == null && this.helper.phone;
}
},
methods: {
...mapActions(['createUser']),
validateObj,
validateNamedRules,
showLoginDialog() {
this.$bvModal.show('login');
},
@@ -107,37 +107,37 @@ export default {
phone: '',
role: 'donor'
},
this.signUpValidationResults = [null];
this.signUpValidationResults = { phone: null };
this.helper = {
phone: false
};
},
async signUp() {
this.signUpValidationMessages = [
'Invalid Phone number. Must start with 7 and be 9 digits long'
];
this.signUpValidationMessages = {
phone: validationMessages.phone,
}
this.helper = {
phone: false,
password: false
};
this.signUpValidationResults = this.validateObj(this.signUpCreds, this.signUpValidationRules);
if (this.googleUser && this.signUpValidationResults[0]) {
this.signUpValidationResults = this.validateNamedRules(this.signUpCreds, this.signUpValidationRules);
if (this.googleUser && !Object.values(this.signUpValidationResults).includes(false)) {
await this.createUser({
phone: `254${this.signUpCreds.phone}`,
googleIdToken: this.googleUser.getAuthResponse().id_token
});
if (!this.user) {
this.signUpValidationMessages = [
'Sign-up failed. Phone number already assigned to existing account'
];
this.signUpValidationResults = [false];
this.signUpValidationMessages = {
phone: validationMessages.phone
}
this.signUpValidationResults = { phone: false };
}
else {
this.signUpCreds = {
phone: '',
role: 'donor'
},
this.signUpValidationResults = [true];
this.signUpValidationResults = { phone: true };
this.$bvModal.hide('google-sign-up');
}
}
Loading

0 comments on commit 31dfd7d

Please sign in to comment.