def register(): if request.method == "POST": username = request.form["username"] email = request.form["email"] pw = request.form["password"] pw2 = request.form["password2"] if pw != pw2: flash("The passwords you submitted don't match, please try again.") return redirect(url_for('register')) if db.userexists(username): flash("The username you submitted is already taken, please try again.") return redirect(url_for('register')) if db.emailexists(email): flash("The email you submitted already has an account tied to it, please try again.") return redirect(url_for('register')) else: db.adduser(username,email,pw) flash("You've sucessfully registered, now login!") return redirect(url_for('login')) else: if session['name']!=None: flash("You're already logged in, so you can't register for a second account!") page = session.pop('nextpage','/') return redirect(page) return render_template("register.html")
def add_user(): if request.method == "GET": return render_template("adduser.html") if request.method == "POST": data = dict((k,v[0]) for k,v in dict(request.form).items()) print data print [ n.values() for n in userlist(["name"]) ] if data["name"] in [ n.values()[0] for n in userlist(["name"]) ]: errmsg = "username is exist" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata if not data["name"] or not data["password"] or not data["role"]: errmsg = "username or password or role not null" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata if data["password"] != data["re_password"]: errmsg = "The two passwords you typed do not match" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata fields = ["name","name_cn","password","mobile","email","role","status"] values = [ '%s'%data[x] for x in fields] userdic = dict([(k,values[i]) for i,k in enumerate(fields)]) adduser(userdic) rdata = json.dumps({"tag":1}) return rdata
def register(): if request.method == "POST": username = request.form["username"] email = request.form["email"] pw = request.form["password"] pw2 = request.form["password2"] if pw != pw2: flash("The passwords you submitted don't match, please try again.") return redirect(url_for('register')) if db.userexists(username): flash( "The username you submitted is already taken, please try again." ) return redirect(url_for('register')) if db.emailexists(email): flash( "The email you submitted already has an account tied to it, please try again." ) return redirect(url_for('register')) else: db.adduser(username, email, pw) flash("You've sucessfully registered, now login!") return redirect(url_for('login')) else: if session['name'] != None: flash( "You're already logged in, so you can't register for a second account!" ) page = session.pop('nextpage', '/') return redirect(page) return render_template("register.html")
def add_user(): if request.method == "GET": return render_template("adduser.html") if request.method == "POST": data = dict((k,v[0]) for k,v in dict(request.form).items()) print data print checkuser({"name":data["name"]},"name") if data["name"] in checkuser({"name":data["name"]},"name"): errmsg = "username is exist" return json.dumps({"tag":1,"msg":errmsg}) adduser(data) return json.dumps({"tag":0})
def adduser(): msg = "" if request.method == "POST": '''data:post提交的用户与密码字典''' user_dic = dict((k, v[0]) for k, v in dict(request.form).items()) '''sql_user:数据库用户列表''' sql_user = [ x['username'] for x in db.query('users', app.config.get('FIELDS')) ] if user_dic['username'] in sql_user: msg = u"用户已经存在" else: user_dic['create_time'] = datetime.datetime.now() t_dict = ["%s='%s'" % (k, v) for k, v in user_dic.items()] db.adduser('users', t_dict) msg = u"添加用户成功" return redirect('index') else: return render_template('account/adduser.html', msg=msg)
def signup(): if current_user.is_authenticated: data=get_limit_blog(current_user.username) return render_template('dashboard.html',user=current_user,data=data,n=0) message='' if request.method=="POST": user_name=request.form['user_name'] password=request.form['password'] email=request.form['email'] repass=request.form['re_password'] if repass==password and user_name and email: try: adduser(email,user_name,password) message="User created successfully" return render_template('signup.html',message=message) except: message="User already Exist" return render_template('signup.html',message=message) message="Data Insufficient" return render_template('signup.html',message=message)
def facebook_authorized(resp): if resp is None: return 'Access denied: reason=%s error=%s' % ( request.args['error_reason'], request.args['error_description'] ) session['oauth_token'] = (resp['access_token'], '') session['token'] = resp['access_token'] me = facebook.get('/me') session['name'] = me.data['name'] fburl = "https://graph.facebook.com/v2.2/me?access_token=" + urllib.quote_plus(str((session["token"]))) req = urllib2.urlopen(fburl) result = req.read() d = json.loads(result) # a = open('sample.json').read() # d = json.loads(a) session['id'] = d['id'] if not db.idexists(session['id']): db.adduser(session['name'],session['id'],me.data['email']) return redirect(url_for('home')) return redirect(url_for('index'))
def add_user(): if request.method == "GET": return render_template("adduser.html") if request.method == "POST": data = dict((k,v[0]) for k,v in dict(request.form).items()) print data if data["name"] in [ n.values() for n in userlist(["name"]) ]: errmsg = "username is exist" return render_template("adduser.html",msg=errmsg) if not data["name"] or not data["password"] or not data["role"]: errmsg = "username or password or role not null" return render_template("adduser.html",msg=errmsg) if data["password"] != data["re_password"]: errmsg = "The two passwords you typed do not match" print session.get("username") return render_template("adduser.html",msg=errmsg) fields = ["name","name_cn","password","mobile","email","role","status"] values = [ '%s'%data[x] for x in fields] userdic = dict([(k,values[i]) for i,k in enumerate(fields)]) adduser(userdic) return redirect("/")
def subscribe(): data = request.form firstname = data['firstname'].strip() lastname = data['lastname'].strip() email = data['email'].strip() if (verify(email) == False): text = "Invalid Email" return render_template('error.html', text=text, again=True) url = 'https://www.google.com/recaptcha/api/siteverify' response = data['g-recaptcha-response'] secret = '6Ld2jGAUAAAAAM9VAACLMcFnsNlaiAHHZCsITeeQ' params = {'secret': secret, 'response': response} data = requests.post(url, data=params).json() status = data['success'] print firstname + '<br>' + lastname + '<br>' + email + '<br>' + str(status) if (data['success'] == True): if (db.adduser(firstname, lastname, email)): mail = Mail(app) msg = Message('Confirm Your Email', sender=('Abhishek Balam', '*****@*****.**'), recipients=[email]) msg.html = render_template('confirm.html', name=firstname, email=email) mail.send(msg) return render_template('info.html') else: text = 'User Already Exists' return render_template('error.html', text=text, again=True) else: text = 'Invalid Captcha' return render_template('error.html', text=text, again=True)
def new_user(username, password): return db.adduser(username, encrypt(password))
errmsg = "username is exist" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata if not data["name"] or not data["password"] or not data["role"]: errmsg = "username or password or role not null" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata if data["password"] != data["re_password"]: errmsg = "The two passwords you typed do not match" rdata = json.dumps({"tag":0,"msg":errmsg}) return rdata fields = ["name","name_cn","password","mobile","email","role","status"] values = [ '%s'%data[x] for x in fields] userdic = dict([(k,values[i]) for i,k in enumerate(fields)]) adduser(userdic) rdata = json.dumps({"tag":1}) return rdata @app.route("/delete") @login_required def del_user(): uid = request.args.get("uid") delete(uid) return "ok" @app.route("/update",methods=["GET","POST"]) @login_required def update(): if request.method == "GET": uid = request.args.get("id")