Skip to content

Commit

Permalink
certificate veriffication
Browse files Browse the repository at this point in the history
  • Loading branch information
pv-912 committed Nov 28, 2018
1 parent 5d9561f commit 7dc2829
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
21 changes: 21 additions & 0 deletions controllers/api/ca/ca_temp_user_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,24 @@ exports.getProfile = function (req, res) {
res.json({ success: true, msg: 'Profile Data', body: user });
})
};

exports.fetch_certificates = function (req, res) {
if(req.locals && req.locals.email){
Temp_User.findOne({
email: req.locals.email
})
.select('name thomso_id college verified payment_type')
.exec(function (err, user) {
if (err) {
return res.status(400).send({ success: false, msg: 'Unable to connect to database. Please try again.', error: err })
}
if (!user) {
return res.status(400).send({ success: false, msg: 'User not found' });
} else if (!user.verified) {
return res.json({ success: true, isVerified: false, msg: 'User Data Found', body: { email: user.email, name: user.name } });
} else {
return res.json({ success: true, isVerified: true, msg: 'User Data Found', body: user });
}
});
}
};
37 changes: 37 additions & 0 deletions controllers/api/main/participant_controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Main_User = require('../../../models/main/Main_User');
// var CA_User = require('../../../models/ca/CA_Temp_User');
var MUN_Answer = require('../../../models/mun/MUN_Answer');
var EventSchema = require('../../../models/main/Thomso_Event');
var Winner = require('../../../models/coordinators/Winner_List');
Expand Down Expand Up @@ -187,6 +188,42 @@ exports.fetch_certificates = function (req, res) {
}
};

exports.certificate_verifications_participant = function(req, res){
if ( req.body && req.body.thomso_id) {
// console.log(req.body)
req.body.thomso_id = req.body.thomso_id.trim()

Main_User.findOne({thomso_id: req.body.thomso_id})
.select('thomso_id name college payment_type')
.exec(function (err, user) {
if (err) {
return res.status(400).send({ success: false, msg: 'Unable to connect to database. Please try again.' });
}
res.json({ success: true,body:user, msg: "Fetched" })
});
} else {
res.status(400).send({ success: false, msg: 'User Not Found' });
}
}

exports.certificate_verifications_winner = function(req, res){
if ( req.body && req.body.thomso_id) {
// console.log(req.body)
req.body.thomso_id = req.body.thomso_id.trim()

Winner.find({thomso_id: req.body.thomso_id})
.select('thomso_id name college position event_name')
.exec(function (err, user) {
if (err) {
return res.status(400).send({ success: false, msg: 'Unable to connect to database. Please try again.' });
}
res.json({ success: true,body:user, msg: "Fetched" })
});
} else {
res.status(400).send({ success: false, msg: 'User Not Found' });
}
}

exports.munAnswer = function (req, res) {
if (req.locals._id && req.locals.email && req.body.answerOne && req.body.answerTwo && req.body.answerThree) {
var data = {
Expand Down
2 changes: 2 additions & 0 deletions routes/ca/temp/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ router.get('/fbtoken', tempControls.checkToken);

router.get('/profile', tempControls.getProfile);

router.get('/fetch_certificate', TempCATokenMiddleware.verify, tempControls.fetch_certificates);

module.exports = router;
5 changes: 5 additions & 0 deletions routes/main/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ router.post('/auth/verify', MainUserTokenMiddleware.verifyUser, participantRegis
router.get('/auth/resend', MainUserTokenMiddleware.verifyUser, participantControl.resendOTP);
router.post('/auth/login', participantRegister.participant_login);


// -> /main/resetPassword
router.post('/auth/resetEmail', participantRegister.reset_password_email);
router.post('/auth/resetPassword', participantRegister.reset_password);
Expand All @@ -49,5 +50,9 @@ router.post('/addParticipant', MainUserTokenMiddleware.verify, eventControl.addP
router.post('/removeParticipant', MainUserTokenMiddleware.verify, eventControl.removeParticipant);

router.post('/answerMUN', MainUserTokenMiddleware.verify, participantControl.munAnswer);
router.post('/certiVerifyParticipant', participantControl.certificate_verifications_participant);
router.post('/certiVerifyWinner', participantControl.certificate_verifications_winner);



module.exports = router;
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ const PronitesIndex = Loadable({
loader: () => import("./components/beta/pronites/Index"),
loading: () => <Loader />
})
const CertificateVerification = Loadable({
loader: () => import("./components/CertificateVerification/Index"),
loading: () => <Loader />
});
class App extends Component {
constructor() {
super();
Expand Down Expand Up @@ -246,6 +250,7 @@ class App extends Component {
<Route path="/cupid" component={Cupid} />
<Route path="/mun" component={MUNIndex} />
<Route path="/super" component={SuperAdminIndex} />
<Route path="/verify" component={CertificateVerification} />
{/* <Route path="/xpression" component={Xpression} /> */}
{/* <Route component={Error404} /> */}
</React.Fragment>
Expand Down
94 changes: 94 additions & 0 deletions src/components/CertificateVerification/Index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react'
import FetchApi from "../../utils/FetchAPI";

export default class VerifyCertificate extends React.Component {
constructor(){
super();
this.state = {
errors:'',
user:[],
userWinner:[],
thomso_id:''
}
}

onChange = (e) => {
const name = e.target.name;
const value = e.target.value;
this.setState({[name]: value, error:''});
}

onSubmit = (e)=>{
e.preventDefault();
const thomso_id = this.state.thomso_id;
let data = {thomso_id};
FetchApi('POST','/api/main/certiVerifyParticipant',data,null)
.then(res => {
if(res && res.data){
if(res.data.success){
// console.log(res.data.body)
this.setState({user:res.data.body})
}
else this.setState({errors:'No User With This ID'})
}
})
.catch( e=> {
if(e & e.response && e.response.data && e.response.data.msg) this.setState({errors:e.response.data.msg})
else this.setState({errors:'Something Went Wrong'})
})

FetchApi('POST','/api/main/certiVerifyWinner',data,null)
.then(res => {
if(res && res.data){
if(res.data.success){
// console.log(res.data.body)
this.setState({userWinner:res.data.body})
}
else this.setState({userWinner:[]})
}
})
.catch( e=> {
if(e & e.response && e.response.data && e.response.data.msg) this.setState({errors:e.response.data.msg})
else this.setState({errors:'Something Went Wrong'})
})
}


render(){
let {errors, user, userWinner} = this.state;
return(
<div>
{errors ?
<div style={{textAlign: 'center', color: 'red', fontWeight: '600'}}>
{errors}
</div>
: null}
<form onSubmit={this.onSubmit}>
<h2>Enter Your Thomso Id</h2>
<label htmlFor="inputUsername">Thomso ID</label>
<input
id="inputUsername"
type="text"
placeholder="Thomso ID"
name="thomso_id"
autoCorrect="off"
autoCapitalize="off"
value={this.state.thomso_id}
onChange={this.onChange}
required
/>
<button type="submit">Fetch Certificate Details</button>
</form>

{(user && user.name) ?
<div>This is to certify that Mr. {user.name} from {user.college} has participated in Thomso'18.<br/> <br/> <br/></div>
:
<span>{errors}</span> }
{(user && user.name && userWinner && userWinner.length>0)?
userWinner.map( (data,i )=>
<div key={i}>This is to certify that Mr. {user.name} from {user.college} has got {data.position} in {data.event_name}</div>
) : null}
</div>
)
}
}
2 changes: 1 addition & 1 deletion src/components/main/certificates/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class CertificateIndex extends Component {
<button type="submit">Submit</button>
</div>
<div className="certificate-link">
<a target="_black" href="http://bit.ly/esthomso">Download this app from this link only</a>
<a target="_black" href="http://bit.ly/esthomso">Download this app from this link only (http://bit.ly/esthomso) </a>
</div>

</div>
Expand Down

0 comments on commit 7dc2829

Please sign in to comment.