def home(): if request.method == 'POST': type = request.args.get('t', 'L') if type == 'R': #recover password _send_mail(request.form['username'],'activate',{'url':request.url_root+url_for('register',v=_activecode(g.db,request.form['username']))}) return jsonify(dict(msg='Validate Email sent successfully',type = 'suc')) elif type == 'L': #user login user_id = _loginuser(g.db,request.form['username'],request.form['password']) if user_id: session['user_id'] = user_id session['email'] = request.form['username'] flash('You were logged in','suc') _loguser(g.db,user_id,'Login',request.remote_addr) return redirect(url_for('trade')) else: g.login_failed = request.form['username'] return render_template('home.html',fbmail=app.config['FEEDBACKMAIL'])
def register(): g.u = _update_user(g.db,session) if request.method == 'POST': response = captcha.submit( request.form['recaptcha_challenge_field'], request.form['recaptcha_response_field'], app.config['RECAP']['private_key'], request.remote_addr, ) if not response.is_valid: flash('Incorrect recaptcha','err') elif not validateEmail(request.form['username']): flash('Not validate Email','err') elif request.form['password'] <> request.form['password2']: flash('Password not Match','err') elif len(request.form['password']) < 6: flash('Password too Short','err') else: res = _createuser(g.db,request.form['username'],request.form['password'],request.form['referrer']) if res == True: _send_mail(request.form['username'],render_template("email/activate.html",para={'user': request.form['username'].split('@')[0].upper(), 'url':url_for('register',v=_activecode(g.db,request.form['username']))})) #'activate',{'url':request.url_root+url_for('register',v=_activecode(g.db,request.form['username']))}) flash('New Account was successfully created','suc') return render_template('register.html',type='C',email=request.form['username']) else: flash(res,'err') else: session.pop('user_id', None) vcode = request.args.get('v', False) if vcode: res = _activeuser(g.db,vcode) if res is not False: flash('Your account had been activated.','suc') session['user_id'] = res[0] session['email'] = res[1] return render_template('register.html',type='A') else: abort(401) rcode = request.args.get('r', False) ref = _dercode(rcode) session.update(ref) return render_template('register.html',type='O',capthtml=captcha.displayhtml(app.config['RECAP']['public_key'],True))
def feedback(): _send_mail(app.config['FEEDBACKMAIL'],render_template("email/feedback.html",category=request.form['category'],msg=request.form['msg'])) msg = dict(msg='Feed back sent successfully.',type = 'suc') return jsonify(msg)
def account(): if 'user_id' not in session: return redirect(url_for('home')) if request.method == 'POST': type = request.args.get('t', 0) if type == 'P': #reset password if _loginuser(g.db,session['email'],request.form['opassword']): _update_pass(g.db,session['email'],request.form['password']) msg = dict(msg = 'Password Changed Successfully.',type ='suc') else: msg = dict(msg='Orignal Password Not Match.',type = 'err') return jsonify(msg) elif type == 'Q': #reset capital password if _vali_cpass(g.db,session['email'],request.form['opassword']): _update_cpass(g.db,session['email'],request.form['password']) if request.form['opassword'] == "not set yet": flash('Capital Password Set Successfully.','suc') return jsonify({'goto':url_for("account",tab=3)}) msg = dict(msg = 'Capital Password Changed Successfully.',type ='suc') else: msg = dict(msg='Orignal Capital Password Not Match.',type = 'err') return jsonify(msg) elif type == 'E': #resend email _send_mail(session['email'],render_template("email/activate.html",para={'user': session['email'].split('@')[0].upper(), 'url':url_for('register',v=_activecode(g.db,session['email']))})) #_send_mail(session['email'],'activate',{'url':request.url_root+url_for('register',v=_activecode(g.db,session['email']))}) msg = dict(msg='Validate Email sent successfully',type = 'suc') return jsonify(msg) elif type == 'I': #invite email if not validateEmail(request.form['email']): flash('Not validate Email','err') elif _change_invitenum(g.db,session['user_id'],-1): _send_mail(request.form['email'],render_template("email/invite.html",para={'user': request.form['email'].split('@')[0].upper(), 'url':url_for('register',r = _enrcode(session['user_id'],request.form['email'])),'refer':session['email'].split('@')[0].upper()})) flash('Invite Email Sent.','suc') return jsonify({'goto':url_for("account",tab=0)}) else: msg = dict(msg='Not Enough Email Invite.',type = 'err') return jsonify(msg) elif type in ['C','D','S']: #new ,modify and settle contract cid = long(request.form['id']) if cid == 0 or gv_contract[cid]['owner'] == session['email']: if type == 'C': msg,cid = _modify_cont(g.db,cid,request.form['code'],request.form['btc_multi'],request.form['opendate'],request.form['opentime'],request.form['settledate'],request.form['settletime'],request.form['leverage'],\ request.form['fullname'],session['user_id'],request.form['twitter_id'],request.form['write_fee'],request.form['region'],request.form['sector'],request.form['description'],request.form['movelimit']) elif type == 'D': #delete msg = _delete_cont(g.db,cid) elif type == 'S': #settle msg = _settle_cont(g.db,cid,request.form['settlepoint'],request.form['settleproof']) else: msg = dict(msg='Contract Owner Not Match.',type = 'err') if msg['type'] == 'suc': flash(msg['msg'],msg['type']) _update_contract(g.db,cid,'D') return jsonify({'goto':url_for("account",tab=2)}) else: return jsonify(msg) g.u=_update_user(g.db,session,['positions','info','rtvol','log']) tab = request.args.get('tab', 0) return render_template('account.html',tab=tab)