export default function Alert({className, type, title, name, message, code}){ debug('name: ', name) return ( <div className={`alert alert-${type} text-center ${className}`} role="alert"> {title && ( <h3>{title}</h3> )} {name && ( <div>{tr.t('An error occured')} <div>{name}</div> </div> )} {message && ( <div>{tr.t(message)}</div> )} {code && ( <div> <div>{tr.t('Status Code')}</div> <div>{code}</div> </div> )} </div> ) }
Challenge.model.populate(userChallenges, {path: 'challenge.waypoints', model:'Waypoint'}, function(err, userChallenges){ if(err) return res.apiError('1000', i18n.t('1000')); async.each(userChallenges, function(userChallenge, cb) { userChallenge.getMediaHavenUrls(function(userChallenge) { cb(); }); }, function(err) { return res.apiResponse({ challenges: userChallenges }); }); });
User.model.findOne().where({'email': req.body.email}).exec(function(err, user) { if (err) return next(err); if (!user) { req.flash('error', i18n.t("error.NO_USER_FOR_EMAIL")); return next(); } user.resetPasswordEmail(function(err) { if (err) { req.flash('error', i18n.t("error.ERROR_SENDING_RESET_PASSWORD_EMAIL")); return next(); } req.flash('success', i18n.t("forgotpassword.PASSWORD_RESET_EMAIL_SUCCESS")); res.redirect('/signin'); }); });
create: function (req, res) { if (req.route.method != 'post') { return res.send(400, { message: i18n.t('commonAPI.unsupported','Unsupported operation.') } ); } var proj = _.extend(req.body || {}, req.params); Project.create(proj, function (err, newProj) { if (err) { return res.send(400, { message: i18n.t('projectAPI.errMsg.create','Error creating project.') } ); } // Associate the user that created this project with the project ProjectOwner.create({ projectId: newProj.id, userId: req.user[0].id }, function (err, projOwner) { if (err) { return res.send(400, { message: i18n.t('projectAPI.errMsg.ownerStore','Error storing project owner.') } ); } newProj.owners = [ projOwner ]; return res.send(newProj); }); }); },
wrapper: props => { const {children, loading, empty, error, ...others} = props return ( <tbody {...others}> {(loading || error || empty) ? ( <tr> <td colSpan={100} style={{textAlign: 'center'}}> {loading && <Loading className='loading-indicator' delay={0} type='cylon' />} {error && error.toString()} {empty && i18next.t('empty')} </td> </tr> ) : children} </tbody> ) }
User.model.findOne().where({'_id': req.user.id, 'email': req.body.email}).exec(function(err, user) { if (err) return next(err); if (!user) { req.flash('error', i18n.t("error.INCORRECT_EMAIL_ERROR")); return next(); } user.unsubscribe = true; user.save(function(err) { if (err) { req.flash('error', i18n.t("unsubscribe.UNSUBSCRIBE_ERROR")); return next(); } req.flash('success', i18n.t("unsubscribe.UNSUBSCRIBE_SUCCESS", {appName:i18n.t("APP_NAME")})); res.redirect('/'); }); });
returnedObjectHandler: function(key, value, options) { if (!hasOwn.call(options, "choice") || "number" !== typeof options.choice || !hasOwn.call(value, "choice") || "object" !== typeof value.choice) { return "key '" + this.ns[0] + ":" + key + " (" + this.lng + ")' returned an object instead of string."; } const keys = Object.keys(value.choice).sort(intComparator); let choice = keys[0]; value = options.choice; for (let i = 0, len = keys.length; i < len; i++) { const num = parseInt(keys[i], 10); if (value >= num) { choice = keys[i]; } } return i18n.t(key + ".choice." + choice, options); }
function(err) { if(err) { return res.apiError('1003', i18n.t('1003')); } if(!newUser.welcomeMailSend) keystone.agenda.now('welcome email',{userId: newUser.id}); if(req.files && req.files['photo_upload']) { var photo = { }; photo.photo = req.files['photo_upload']; newUser.getUpdateHandler(req).process(photo, { fields: 'photo' }, function(err) { if(err) { return res.apiError('1009', i18n.t('1009')); } return res.apiResponse({ success: true }); }); } else return res.apiResponse({ success: true }); });
function mapStateToProps(state, props) { if (props.action === 'payment') { const fields = [ { name: 'value', label: i18next.t('commission:formAmount'), value: (_.has(props, 'value')) ? props.value : '', validation: 'uint' } ] return { fields, initialValues: _.zipObject(_.map(fields, 'name'), _.map(fields, 'value')), } } return {} }
function getEntityTranslation (key, suffix) { if (key == null) { key = FlowRouter.getParam('key') } const attributeParts = [key] if (suffix != null && typeof (suffix) === 'string') { attributeParts.push(suffix) } const routeNameParts = FlowRouter.getRouteName().split('.') routeNameParts.pop() routeNameParts.splice(1, 0, 'entity') return i18next.t(routeNameParts.concat(attributeParts).join('.').replace(/_/g, '.')) }
error: function(error) { if ( self.willBeDestroyed ) return false; self.onSendError(); var dfd; if (error.responseJSON[0] === 'Access denied for user anonymous') { Dialog.confirm({ message: i18n.t('pages.observation.dialogs.need_login'), callback: function(result) { if (result) { self.session.afterLoggedAction = { name: 'showObsAndTransmit', options: { id: self.observationModel.get('id') } }; self.session.set('needLogin', true); Router.getInstance().startOutOfHistory(); if (self.user.isAnonymous()) Router.getInstance().navigate('user-selector', { trigger: true }); else Router.getInstance().navigate('login/' + self.user.get('id'), { trigger: true }); } } }); //session.redirectAfterLogin = '******'+self.observationModel.get('id')+'?action=transmit'; /*var message = i18n.t('pages.observation.dialogs.need_login'); if (user.get('firstname') || user.get('lastname') || user.get('email')) message = i18n.t('pages.observation.dialogs.need_complete_registration'); dfd = Login.openDialog({ message: message });*/ } else { Dialog.alert({ closable: true, message: error.responseJSON }); } /*dfd.then(function() { Dialog.alert(i18n.t('pages.observation.dialogs.need_complete')); });*/ },
render() { const {top} = this.state; const {totalCount, otherAction, data} = this.props; const isOtherAction = otherAction !== undefined; const paginateCount = (data && data.length < top) ? data.length : top; return ( <div data-focus='list-with-pagination'> <ComponentToConnect {...this.props} /> <div data-focus='pagination'> <div data-focus='pagination-indicators'>{`${paginateCount} ${i18next.t(`focus.search.paginate.totalCount`, {count: paginateCount})}`}</div> <div data-focus='pagination__actions'> {!isOtherAction && <Button data-focus='paginate.show.next' label='focus.search.paginate.show.next' onClick={this._onClickNext} />} {isOtherAction && <Button data-focus='paginate.other.action' label='focus.search.paginate.other.action' onClick={this._otherAction} />} </div> </div> </div> ); }
function mapStateToProps(state, props) { let input = {} if (_.has(props, 'input')) { input = props.input } return { fields: [ { name: 'value', label: i18next.t('tokenAcl:formAmount'), placeholder: '10', validation: 'uint', disabled: true }, ], initialValues: input, } }
app.get('/chat/talk',function(req, res) { // TODO: Get talk smart, do not read everything !! var t = req.query.text; if (t.length>50) { t = t.substring(0,50)+';'+i18n.t('moretext'); } var reqst = http.get( { host:'translate.google.com', path:'/translate_tts?tl='+req.locale+'&q='+escape(t), headers:{'User-Agent':'Mozilla/5.0 (Windows NT 6.0; rv:26.0) Gecko/20100101 Firefox/33.0'} }, function(response) { //handle the response res.setHeader('Content-Type','audio/mpeg'); response.pipe(res); }); reqst.on('error', function(err) { logger.error('Talk translate error: ' + err.message); }); });
_toggleStar(e, isStarred, starKey) { e.stopPropagation() const { userFirebase, item } = this.props if (!userFirebase) { return this.props.toggleModalLogin() } if (isStarred) { if (this._isItemTypeStar()) { if (!confirm(i18next.t('Star__delete__confirm'))) return false } firebaseUtils.stars.destroy(userFirebase.auth.uid, starKey) .then() .catch(() => Alert.error(i18next.t('error__stars__destroy') + i18next.t('tryAgainLater'))) } else { firebaseUtils.stars.create(userFirebase.auth.uid, item) .then(() => Alert.info(i18next.t('success__stars__create'))) .catch(() => Alert.error(i18next.t('error__stars__create') + i18next.t('tryAgainLater'))) } }
handlebars.registerHelper("t", function (i18n_key, options) { var opts = { wrapWithKey: true }; _.extend(opts, options.hash); var result = i18next.t(i18n_key, opts); var attrs = ["data-t=\"" + i18n_key + "\""]; _.each(opts, function (val, key) { if (_.isString(val || _.isFinite(val))) { return attrs.push("data-" + key + "=\"" + val + "\""); } }); if (opts['wrapWithKey']) { return "<span " + (attrs.join(' ')) + ">" + (new handlebars.SafeString(result)) + "</span>"; } else { return new handlebars.SafeString(result); } });
UserGeneratedContent.model.find({waypoint: req.params.wpid, challenge: req.params.challengeid, user: {'$ne': req.user._id }}).populate('user challenge userchallenge waypoint').sort({createdAt: 'desc'}).exec(function(err, ugcList) { if(err) return res.apiError('1000', i18n.t('1000')); if(!ugcList) return res.apiResponse({ ugc: null }); async.detectSeries(ugcList, function(ugc, cb) { ugc.getMediaHavenUrls(function(item) { if((item.contentText && item.contentText !=='' )|| (item.content && item.content.url !=='' && item.content.url !== undefined)) { return cb(true); } else { cb(false); } }); }, function(result) { if(result === undefined) { return res.apiResponse({ ugc: null }); } return res.apiResponse({ ugc: result }); }); });
UserChallenge.model.find({'user': req.params.id, complete: completed}).populate('challenge user completedWP hintsUsed').exec(function(err, userChallenges) { if(err) return res.apiError('1000', i18n.t('1000')); Challenge.model.populate(userChallenges, {path: 'challenge.waypoints', model:'Waypoint'}, function(err, userChallenges){ if(err) return res.apiError('1000', i18n.t('1000')); async.each(userChallenges, function(userChallenge, cb) { userChallenge.getMediaHavenUrls(function(userChallenge) { cb(); }); }, function(err) { return res.apiResponse({ challenges: userChallenges }); }); }); });
create : function(req, res){ var user = new User(); user.name = req.body.name; user.note = req.body.note; req.assert('name', 'can not be empty.').notEmpty(); var valerr = req.validationErrors(); if (valerr){ req.flash('valerr', valerr); res.render('user/new', { title: i18n.t('user.model'), user: user, flash: req.flash() }); return; } user.create(function(err, results) { if (err){ req.flash('err', err); res.render('users/new', { title: i18n.t('user.model'), user: user, flash: req.flash() }); } res.redirect('/users'); }); },
render() { const {FacetBlock, data, facetAction} = this.props; return ( <div data-focus='facet-panel'> <h4>{i18next.t('focus.search.facets')}</h4> {data.map( facetDescriptor => { if(facetDescriptor.values.length > 1 || facetDescriptor.selected) { return <FacetBlock key={facetDescriptor.code} {...facetDescriptor} selected={facetDescriptor.selected} selectFacet={(value) => facetAction(value, false)} deleteFacet={value => facetAction(value, true)} /> } else { return null; } } )} </div> ); }
User.model.findOne({email_lowercase: userData.email.toLowerCase()}, function(err, user) { if(err || user) { return res.apiError('1002', i18n.t('1002')); } newUser.getUpdateHandler(req).process(userData, {fields:'username, email, password, gender, birthyear, isAdmin, score'}, function(err) { if(err) { return res.apiError('1003', i18n.t('1003')); } if(!newUser.welcomeMailSend) keystone.agenda.now('welcome email',{userId: newUser.id}); if(req.files && req.files['photo_upload']) { var photo = { }; photo.photo = req.files['photo_upload']; newUser.getUpdateHandler(req).process(photo, { fields: 'photo' }, function(err) { if(err) { return res.apiError('1009', i18n.t('1009')); } return res.apiResponse({ success: true }); }); } else return res.apiResponse({ success: true }); }); });
onFormSubmit: function(e) { var self = this; e.preventDefault(); var errors = this.formObs.validate(); if (errors) return false; if (this.$el.hasClass('form-status-unsaved')) { this.saveObs(); } else if ( navigator.onLine ) { if (this.$el.hasClass('form-status-shared-0')) { // this.checkBounds().done(function() { self.sendObs(); /// }); } else if (this.$el.hasClass('form-status-shared-1')) this.shareObs(); } else { Dialog.alert(i18n.t('pages.observation.dialogs.need_login_offline')); } },
render() { const {code, deleteFacet, FacetComponent, FacetSelectedComponent, label, selected, selectFacet, selectedFacets, values} = this.props; return ( <div data-focus='facet-block' data-selected={selected}> <h3>{i18next.t(`search.facets.items.${label}`)}</h3> {selected ? <ul> { isArray(selectedFacets) ? selectedFacets.map(value => ( <FacetSelectedComponent key={code} label={(values.find(element => element.code === value)).label} code={value} onClick={selectedValue => deleteFacet({code: code, values: selectedValue})} /> )) : <FacetSelectedComponent key={code} label={(values.find(element => element.code === selectedFacets)).label} code={selectedFacets} onClick={selectedValue => deleteFacet({code: code, values: selectedValue})} /> } </ul> : <ul> { values.map(facet => ( <FacetComponent key={facet.code} {...facet} onClick={selectedValue => selectFacet({code: code, values: selectedValue}) } /> )) } </ul> } </div> ); }
User.model.findOne().where({'email': req.body.email, resetPasswordKey: req.body.resetPasswordKey}).exec(function(err, user){ if(err || !user) { return res.apiError('1018', i18n.t('1018')); } var newPassWord = { resetPasswordKey : null, password: req.body['newPassword'], password_confirm: req.body['newPassword_confirm'] }; user.getUpdateHandler(req).process(newPassWord,{ fields: 'password, resetPasswordKey', flashErrors: false }, function(err) { if(err) return res.apiError('1000', i18n.t('1000')); keystone.session.signin(user._id.toString(), req, res, function(user) { user.getMediaHavenUrls(function(user) { return res.apiResponse({ user: user }); }); }, function(err) { return res.apiError('1005', i18n.t('1005')); } ); }); });
Meteor.call("products/archiveProduct", productIds, function (error, result) { let title; if (error) { title = products.length === 1 ? products[0].title || i18next.t("productDetail.archiveErrorTheProduct") : i18next.t("productDetail.theSelectedProducts"); Alerts.toast(i18next.t("productDetail.productArchiveError", { product: title }), "error"); throw new Meteor.Error("Error archiving " + title, error); } if (result) { Router.go("/"); if (products.length === 1) { title = products[0].title || i18next.t("productDetail.theProduct"); Alerts.toast(i18next.t("productDetail.archivedAlert", { product: title }), "info"); } else { title = i18next.t("productDetail.theSelectedProducts"); Alerts.toast(i18next.t("productDetail.archivedAlert_plural", { product: title, count: 0 }), "info"); } } });
exports.getNearby = function(req, res) { var maxDistance = (req.params.distance) ? keystone.utils.number(req.params.distance) : 1000; var location = []; _.each(req.params.location.split(','), function(coordinate){ location.push(keystone.utils.number(coordinate)); }); if(location === [] || location.length < 2) return res.apiError('1026', i18n.t('1026')); Challenge.model.find({status: 1, "location.geo": {$near: { $geometry:{ type: "Point", coordinates: location }, $maxDistance: maxDistance}}}).populate('waypoints').exec(function(err, challenges) { if (err) return res.apiError('1000', i18n.t('1000')); UserChallenge.model.find({user: req.user._id, complete: true}).exec(function (err, userChallenges) { challenges = _.reject(challenges, function (challenge) { var playedBefore = _.find(userChallenges, function (userChallenge) { if (userChallenge.challenge.toString() === challenge._id.toString()) { return true; } return false; }); if (playedBefore && !challenge.repeatable) { return true; } else { return false; } }); async.each(challenges, function (challenge, cb) { challenge.getMediaHavenUrls(function (challenge) { cb(); }); }, function (err) { return res.apiResponse({ challenges: challenges }); }); }); }); }
export function Home() { return ( <div className='layout'> <header> <ArticleListTitle textFieldUnderline={false}/> </header> <div className='content'> <ArticleList /> </div> <footer> <a href={backOfficeUrl} target='_blank'> <FlatButton icon={<i className='material-icons'>exit_to_app</i>} label={i18n.t('extension.footer.button')} primary={true} rippleColor='transparent' style={{width: '100%', textAlign: 'left'}} /> </a> </footer> </div> ); }
ExperienceTicket.model.find({user: req.user.id}).populate('experience').exec(function(err, tickets){ if(err) { return res.apiError('1088', i18n.t('1088')); } if(!tickets) { return res.apiResponse({tickets: []}); } var groupedTickets = _.groupBy(tickets, function(ticket){ return ticket.experience.id; }); var mappedTickets = _.map(groupedTickets, function(ticket){ var ticket = ticket; var result = { experience: ticket[0].experience }; result.myTickets = _.filter(ticket, function(ticket) { return (ticket.user.toString() === req.user._id.toString() && ticket.used===false)}); result.myTickets = (result.myTickets)?result.myTickets.length:0; result.usedTickets = _.filter(ticket, function(ticket) { return (ticket.user.toString() === req.user._id.toString() && ticket.used===true)}); result.usedTickets = (result.usedTickets)?result.usedTickets.length:0; return result; }); async.each(mappedTickets, function(ticket, cb) { ticket.experience.getMediaHavenUrls(function(ticket) { cb(); }); }, function(err) { if(err) { return res.apiError('1088', i18n.t('1088')); } return res.apiResponse({tickets: mappedTickets}); }); });
exports.login = function(req, res) { if(!req.body || !req.body['email']) { return res.apiError('1000', i18n.t('1000')); } User.model.findOne({ email_lowercase: req.body['email'].toLowerCase() }, "-password -username_lowercase -email_lowercase", function(err, user) { if(err){ console.log(JSON.stringify(err)); return res.apiError('1000', i18n.t('1000')); } if(!user){ return res.apiError('1004', i18n.t('1004')); } keystone.session.signin({email: req.body['email'], password: req.body['password']}, req, res, function(user) { user.getMediaHavenUrls(function(user) { return res.apiResponse({ user: user }); }); }, function() { return res.apiError('1005', i18n.t('1005')); } ); }); };
error: function(error) { var errors = error.responseJSON; self.$el.removeClass('block-ui'); $form.removeClass('loading'); if (_.includes(errors, 'email_exists')) { $form.find('input[name="email2"]').val(''); Dialog.confirm({ closable: true, message: i18n.t('validation.errors.email_exists'), callback: function(result) { if (result) { Router.getInstance().navigate('login', {trigger:true}); } } }); } else { Dialog.alert({ closable: true, message: error.responseJSON }); //There is an error but no conflict so we can continue ! self.registerOnLocal(); } },