Esempio n. 1
0
def forgot():
    if request.method == 'POST':
        un = request.form.get('un',"")
        account = models.Account.pull(un)
        if account is None: account = models.Account.pull_by_email(un)
        if account is None:
            flash('Sorry, your account username / email address is not recognised. Please contact us.')
        else:
            newpass = util.generate_password()
            account.set_password(newpass)
            account.save()

            to = [account.data['email']]
            if app.config.get('ADMIN_EMAIL') is not None:
                to.append(app.config.get('ADMIN_EMAIL'))
            fro = app.config.get('ADMIN_EMAIL', "*****@*****.**")
            subject = app.config.get("SERVICE_NAME","") + "password reset"
            text = "A password reset request for account " + account.id + " has been received and processed.\n\n"
            text += "The new password for this account is " + newpass + ".\n\n"
            text += "If you are the user " + account.id + " and you requested this change, please login now and change the password again to something of your preference.\n\n"
            
            text += "If you are the user " + account.id + " and you did NOT request this change, please contact us immediately.\n\n"
            try:
                util.send_mail(to=to, fro=fro, subject=subject, text=text)
                flash('Your password has been reset. Please check your emails.')
                if app.config.get('DEBUG',False):
                    flash('Debug mode - new password was set to ' + newpass)
            except:
                flash('Email failed.')
                if app.config.get('DEBUG',False):
                    flash('Debug mode - new password was set to ' + newpass)

    return render_template('account/forgot.html')
Esempio n. 2
0
def mailer():
    if request.method == 'GET':
        return render_template('contact.html')

    elif request.method == 'POST':
        if app.config['CONTACT_EMAIL'] and not app.config['DEBUG'] and request.values.get('message',False) and not request.values.get('not',False):
            util.send_mail(
                [app.config['CONTACT_EMAIL'] + '>'],
                app.config['CONTACT_EMAIL'],
                'HOII enquiry',
                request.values['message']
            )
            flash('Thanks, your query will be processed soon.', 'success')
            return render_template('contact.html')
        else:
            flash('Sorry, your request was missing something, or we have not enabled the contact form...')
            return render_template('contact.html')
Esempio n. 3
0
def issue(path=''):
    givejson = util.request_wants_json()
    path = path.replace('.json','')

    i = False
    
    if path:
        i = models.Issue.pull(path)

    if request.method == 'GET':
        if givejson:
            resp = make_response( i.data )
            resp.mimetype = "application/json"
            return resp
        else:
            return render_template('issue.html', issue=i)

    elif request.method == 'POST':
        if not i:
            i = models.Issue()

        if request.json:
            i.data = request.json
        elif request.values:
            i.data['about'] = request.values['about']
            i.data['issue'] = request.values['issue']
            i.data['email'] = request.values['email']
        else:
            abort(404)

        # only save an issue about an ID we actually have a record for
        if len(i.data['about']) < 9:
            cid = 'pmid:'
        else:
            cid = 'doi:'
        check = models.Record.pull(cid + i.data['about'].replace('/','_'))
        if check is not None:
            i.save()
        elif givejson:
            abort(404)
        else:
            flash("Sorry, your issue is about an identifier for which we do not hold a record.", 'error')
            return render_template('issue.html', issue=i)

        if app.config['CONTACT_EMAIL'] and not app.config['DEBUG']:
            text = 'Hey, an issue has been raised for ' + i.data['about'] + '\n\nView it at http://oag.cottagelabs.com/issue/' + i.id
            util.send_mail([app.config['CONTACT_EMAIL']], app.config['CONTACT_EMAIL'], "issue raised", text)

        if givejson:
            resp = make_response( i.data )
            resp.mimetype = "application/json"
            return resp
        else:
            flash("Thanks, your issue has been raised", 'success')
            return redirect('/issue/' + i.id)

    elif request.method == 'DELETE' and i:
        i.delete()
        return ""
    else:
        abort(404)