def POST(self): inp = web.input(name=None, email=None, token=None) # creating a new user if inp.name and inp.email and inp.token: ex = model.get_user(name=inp.name) if ex: return render.janrain(inp.name, inp.email, inp.token, "Username taken") ex = model.get_user(email=inp.email) if ex: return render.janrain(inp.name, inp.email, inp.token, "Email already in use") model.new_user(inp.name, inp.email, token=inp.token) user = model.get_user(token=inp.token) session.user = User(user) raise web.seeother("/") # already got a user elif inp.token: data = urllib2.urlopen( "https://rpxnow.com/api/v2/auth_info?apiKey=%s&token=%s" % (JANRAIN_KEY, inp.token)).read() resp = json.loads(data) if resp['stat'] == "ok": prof = resp['profile'] jid = prof['identifier'] user = model.get_user(token=jid) user_mail = model.get_user(email=prof.get('email'), token='') if user: # this janrain ID is in our system model.set_user_meta_by_email(user.email, data) session.user = User(user) raise web.seeother("/") elif prof.get("email") and user_mail: # they used a new account with known email model.set_user_token_by_email(prof['email'], jid) model.set_user_meta_by_email(prof['email'], data) session.user = User(user_mail) raise web.seeother("/") else: return render.janrain(prof.get('preferredUsername', ''), prof.get('email', ''), jid) else: return "Error logging in" return "Missing token"
def POST(self): f = register_form() if not f.validates(): return render.register(f) else: # do whatever is required for registration param = web.input() user_name = param.username user_email = param.email user_password = param.password model.new_user(name=user_name, password=user_password, email=user_email) return user_name + " add success"
def POST(self): data = json.loads(web.data()) try: new_user = model.new_user(data) except Exception, e: web.ctx.status = '400 Bad Request' return
def POST(self): form = addform() if not form.validates(): users = model.get_users() return render.index(users, form) model.new_user(form.d.login, form.d.password, form.d.prefix, form.d.firstname, form.d.lastname, form.d.email, form.d.phone, form.d.addr1, form.d.addr2, form.d.city, form.d.state, form.d.country, form.d.zip, form.d.approved) mailfrom = "rhn-newuser-request@localhost" mailto = "root@localhost" subject = "New User Added" message = "The following user has requested access: %s" % ( form.d.login) web.sendmail(mailfrom, mailto, subject, message) return "Thank you, an email will be sent for Approval."
def POST(self): data = web.data() fn=json.loads(data)['firstname'] ln=json.loads(data)['lastname'] ph=json.loads(data)['phone'] eml=json.loads(data)['email'] un=json.loads(data)['username'] pwd=json.loads(data)['password'] pwd1= hashlib.md5(pwd).hexdigest() dt=json.loads(data)['joined'] p=model.new_user(fn,ln,ph,eml,un,pwd1,0,0,0,dt) return p
def post(self): username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') error, params = stuff.valid_signup(username, password, verify, email) if error: self.render('signup.html', **params) else: password = stuff.make_pw_hash(password) user = model.new_user(username, email, password) self.login(user) self.redirect('/')
def POST(self): register = self.register() if not register.validates(): raise web.seeother('/') fn=register.d.firstname ln=register.d.lastname ph=register.d.phone eml=register.d.email un=register.d.username pwd=register.d.password s=model.new_user(fn,ln,ph,eml,un,pwd,str(date.today())) if s['status']== "Registered": session.loggedin = True session.user = s['username'] #return s raise web.seeother('/updateprofile')
def PUT(self): # Add a new user data = json.loads(web.data()) data['password'] = hashlib.md5(data['password']).hexdigest() new_id = model.new_user(data) # Don't pass the MD5-ed password back, this would be a big security hole data = [{ "username": data['username'], "email": data['email'], "privilege": data['privilege'], # TODO: Check this privilege "id": new_id }] ''' You are going to see the next three lines quite a bit. We use the response headers to make browsers play nicely with us passing back JSON data. We the json.dumps() function to serialize our data dictionary into a JSON structure. If you are getting python errors when trying to use json.dumps you probably have a cyclic reference in what you are trying to serialize. ''' web.header("Content-Type","application/json") web.header("Cache-Control","no-cache") return json.dumps(data)
import model import datetime db = model.connect_db() user_id = model.new_user(db, "*****@*****.**", "securepassword", "Christian") task = model.new_task(db, "A task for Christian", user_id, datetime.datetime.now(), None, "category3", None, 4, "Tuesday") task = model.new_task(db, "The best task OH MY FREAKING GOD", user_id, datetime.datetime.now(), None, "category3", None, 5, "Next year") user_id = model.new_user(db, "*****@*****.**", "awesomepassword", "Gulnara") task = model.new_task(db, "let's drink", user_id, datetime.datetime.now(), None, "category3", None, 1, "in an hour") task = model.new_task(db, "go to sleep", user_id, datetime.datetime.now(), None, "category4", None, 2, "in 2 hours") user_id = model.new_user(db, "*****@*****.**", "yeahyeahyeah", "Lindsay") task = model.new_task(db, "go hiking", user_id, datetime.datetime.now(), None, "category78", None, 3, "sunday") task = model.new_task(db, "read a few books", user_id, datetime.datetime.now(), None, "category54", None, 4, "this weekend")
""" seed.py """ import model db = model.connect_db() # user_id = model.new_user(db, "*****@*****.**", "securepassword", "Christian") # task = model.new_task(db, "Complete this task list", user_id) user_id = model.new_user(db, "*****@*****.**", "password", "Gulnara") task = model.new_task(db, "we did it!", user_id) task = model.new_task(db, "almost done!!", user_id)
def new_user(): user_email= request.form['user_email'] user_pass= request.form['password_field'] user_age= request.form['age_field'] model.new_user(user_email, user_pass, user_age) return redirect("/profile")