Example #1
0
 def post(self):
     name = self.request.get('username')
     password = self.request.get('password')
     verify = self.request.get('verify')
     email = self.request.get('email')
     error = {}
     # let's check if user already exists
     user = User.by_name(name)
     if user:
         error['name'] = "User already exists"
     # let's check if a name it's been introduced and its format
     name_ok = name and validate(name, '^[a-zA-Z0-9_-]{3,20}$')
     if not name_ok:
         error['name'] = "That's not a valid user name"
     # let's check there is a password and its format
     password_ok = password and validate(password, '^.{3,20}$')
     if not password_ok:
         error['password'] = "******"
     # let's check the verify password is the same as the password
     if verify != password:
         error['verify'] = "Your passwords didn't match"
     # not needed, but if there is an email let's check its format
     if email != '':
         if not validate(email, '^[\S]+@[\S]+.[\S]+$'):
             error['email'] = "That's not a valid email"
     # if everything went right, let's introduce our new friend
     if not error:
         pw_hash = make_pw_hash(name, password)
         user = User(name=name, password=pw_hash, email=email)
         user.put()
         # now we logged the user in
         self.login(user)
         self.redirect('/')
     # if something went wrong, let's render again showing the error
     self.render('sign-up.html', name=name, email=email, error=error)
Example #2
0
def fb_login():
    if request.method != "POST":
        return "Error", 404
    user = User.get_by_id(request.form["userID"])
    response = {}

    response["status"] = "existing"
    if not user:
        user = User(id=request.form["userID"],
                    userID=request.form["userID"],
                    name=request.form["first_name"] + " " +
                    request.form["last_name"],
                    email=request.form["email"],
                    rating=2.5,
                    number_ratings=1)
        user.put()

        response["status"] = "new"

    if Admin.get_by_id(user.key.id()):
        session["admin"] = True
    else:
        session["admin"] = False
    session['first_name'] = request.form["first_name"]
    session['last_name'] = request.form["last_name"]
    session['email'] = request.form["email"]
    logged_in(user)
    return json.dumps(response)
Example #3
0
 def post(self):
     name = self.request.get('username')
     password = self.request.get('password')
     verify = self.request.get('verify')
     email = self.request.get('email')
     error = {}
     # let's check if user already exists
     user = User.by_name(name)
     if user:
         error['name'] = "User already exists"
     # let's check if a name it's been introduced and its format
     name_ok = name and validate(name, '^[a-zA-Z0-9_-]{3,20}$')
     if not name_ok:
         error['name'] = "That's not a valid user name"
     # let's check there is a password and its format
     password_ok = password and validate(password, '^.{3,20}$')
     if not password_ok:
         error['password'] = "******"
     # let's check the verify password is the same as the password
     if verify != password:
         error['verify'] = "Your passwords didn't match"
     # not needed, but if there is an email let's check its format
     if email != '':
         if not validate(email, '^[\S]+@[\S]+.[\S]+$'):
             error['email'] = "That's not a valid email"
     # if everything went right, let's introduce our new friend
     if not error:
         pw_hash = make_pw_hash(name, password)
         user = User(name=name, password=pw_hash, email=email)
         user.put()
         # now we logged the user in
         self.login(user)
         self.redirect('/')
     # if something went wrong, let's render again showing the error
     self.render('sign-up.html', name=name, email=email, error=error)
Example #4
0
 def get(self):
     cur_user = users.get_current_user()
     if cur_user:
         existing_user = User.find(cur_user)
         if not existing_user.get():
             # New user
             user_entity = User(user = cur_user)
             user_entity.put()
             greeting = ('Welcome! %s (<a href = "%s">sign out</a>)' %
                         (cur_user.nickname(), users.create_logout_url('/login')))
         else:
             greeting = ('Welcome back, %s (<a href = "%s">sign out</a>)' %
                         (cur_user.nickname(), users.create_logout_url('/login')))
     else:
         greeting = ('<a href="%s">Sign in</a>' % users.create_login_url("/login"))
     self.response.out.write("<html><body>%s</body></html>" % greeting)
Example #5
0
def follow(twitter, handle):
	user_data = follow_user_and_get(twitter, handle)
	if user_data is None:
		return

	user = User.all().filter('screen_name =', handle).get()
	if user is None:
		user = User(screen_name=handle)
	else:
		user.active = True
		if user.location is not None:
			user.put()
			send_success_dm(twitter, handle)
			return

	relocate(twitter, user_data.location, user)
	user.put()
Example #6
0
def signup():
    return login()
    fields = []
    fields.append(
        Field(name="email",
              title="Email",
              the_type='email',
              identifier='email',
              placeholder="Email"))
    fields.append(
        Field(name="name",
              title="Name",
              the_type='name',
              identifier='name',
              placeholder="Name"))
    fields.append(
        Field(name='password',
              title="Password",
              the_type='password',
              identifier='password',
              placeholder='Password'))
    title = "Signup"

    form = Form(fields=fields, title=title)

    if request.method == 'GET':
        return render_template('signup.html', signup_form=form)

    try:
        exists = User.get_by_id(request.form['email'])
        if exists:
            form.error = "Email Taken"
            return render_template('signup.html', signup_form=form)
        else:
            user = User(email=request.form['email'],
                        id=request.form['email'],
                        password=request.form['password'],
                        name=request.form['name'])
            user.put()
            return signed_up(user)
    except KeyError as err:
        form.error = "Email or Password Was Not Filled Out Correctly"
        return render_template('signup.html', signup_form=form)
Example #7
0
 def post(self):
     username = self.request.get('username')
     password = self.request.get('password')
     verify = self.request.get('verify')
     email = self.request.get('email')
     c_username = self.check(username, "^[a-zA-Z0-9_-]{3,20}$")
     c_password = self.check(password, "^.{3,20}$")
     c_email = self.check(email,"^[\S]+@[\S]+\.[\S]+$")   
     error = Error()
     user = getUser(username)
     if not user == None:
         error.name_error = "duplicate user name.  please choose another."
         error.error = True
     if(password != verify):
         error.ver_error = "Password does not match"
         error.error = True
     if c_username == None:
         error.name_error = "Invalid Username"
         error.error = True
     if c_password == None:
         error.pwd_error = "Invalid Password"
         error.error = True
     if(email != "" and c_email == None):
         error.email_error = "Invalid email address" 
         error.error = True   
     if error.error:   
         self.render_register(username, "", "", email,error)
     else :
         #save user in database
         user_class = USER
         if username == ADMINISTRATOR:
             user_class = ADMIN            
         user = User(username=username, password=hash_pw(username,password), email=email, user_class=user_class)
         user.put()
         #set login cookie
         #redirect to index page
         self.redirect('/')
Example #8
0
 def persistUser(self,username,email,password):
     user = User()
     user.username = username
     user.hashed_password = hashlib.sha256(password).hexdigest()
     user.email = email
     return user.put().id()      
Example #9
0
def fb_signup():
    if request.method != "POST":
        return "Error", 404
    user = User(id=request.form["userID"])
    user.put()