def POST(self):
     post = web.input(_method='POST')
     errors = {}
     username = forms.get_or_add_error(post, 'username', errors, lang.NO_FIELD_SUPPLIED('username'))
     
     if not errors:
         result = db.users.find_one({'username':username})
         forms.validate(errors, 'username', lang.NO_CONTACT_FOUND, lambda c: bool(c), (result,))
         
     if result:
         return web.seeother('/users/%s/' % result['username'])
     else:
         return render('/users/search.html', errors=errors)
Example #2
0
    def POST(self):
        post = web.input(_method='POST')
        errors = {}
        username = forms.get_or_add_error(post, 'username', errors,
                                          lang.NO_FIELD_SUPPLIED('username'))
        password = forms.get_or_add_error(post, 'password', errors,
                                          lang.NO_FIELD_SUPPLIED('password'))
        password_again = forms.get_or_add_error(
            post, 'password_again', errors,
            lang.NO_FIELD_SUPPLIED('password again'))

        forms.validate(errors, 'password_again', lang.PASSWORDS_DONT_MATCH,
                       lambda p, p2: p == p2, (password, password_again))

        if username is not None:
            forms.validate(errors, 'username',
                           lang.FIELD_MUST_BE_LEN('Username', 3),
                           lambda u: len(u) >= 3, (username, ))
            forms.validate(
                errors, 'username', lang.USERNAME_TAKEN,
                lambda u: not bool(db.users.find_one({'username': u})),
                (username, ))
        if password is not None:
            forms.validate(errors, 'password',
                           lang.FIELD_MUST_BE_LEN('Password', 5),
                           lambda p: len(p) >= 5, (password, ))

        if errors:
            return render('register.html', errors=errors)
        else:
            users.register(username=username, password=users.pswd(password))
            web.seeother('/login/')
    def POST(self, username):
        post = web.input(_method='POST')
        errors = {}
        user = users.get_user()

        contact = db.users.find_one({'username':username})

        forms.validate(errors, 'username', lang.NO_CONTACT_FOUND, lambda c: bool(c), (contact,))
        if contact:
            forms.validate(errors, 'username', lang.ALREADY_CONNECTED(contact['username']), lambda u, c: ('contacts' not in u) or (c not in u['contacts']), (user, contact))
            forms.validate(errors, 'username', lang.CANT_CONNECT_TO_SELF, lambda u, c: c!=u, (user, contact))

        if contact and not errors:
            #Add to the user's contacts
            if 'contacts' not in user or not user['contacts']:
                user['contacts'] = []
            user['contacts'].append(DBRef('users',contact['_id']))
            
            #Add user to the other persons contacts
            if 'contacts' not in contact or not contact['contacts']:
                contact['contacts'] = []
            contact['contacts'].append(DBRef('users',user['_id']))
            
            #Save them both
            db.users.save(user)
            db.users.save(contact)                                       

        return render('/users/profile.html', profile=contact, errors=errors, connected=self.connected(contact))    
    def POST(self):
        post = web.input(_method='POST')
        errors = {}
        user = users.get_user()
        mode = ''

        #Get all the stuff we want from POST
        if 'from_username' in post:
            mode = 'from'
            other_username = forms.get_or_add_error(post, '%s_username' % mode, errors, lang.NO_FIELD_SUPPLIED('username'))
        else:
            mode = 'to'
            other_username = forms.get_or_add_error(post, '%s_username' % mode, errors, lang.NO_FIELD_SUPPLIED('username'))

        value_pounds = forms.get_or_add_error(post, '%s_value_pounds' % mode, errors, lang.NO_FIELD_SUPPLIED('pounds value'))
        value_pence  = forms.get_or_add_error(post, '%s_value_pence' % mode, errors, lang.NO_FIELD_SUPPLIED('pence value'))
        reason  = forms.get_or_add_error(post, '%s_reason' % mode, errors, lang.NO_FIELD_SUPPLIED('reason'))

        #Process and validate the amount
        try:
            if value_pounds.strip() == '':
                value_pounds = 0
            if value_pence.strip() == '':
                value_pence = 0

            value_pounds = int(value_pounds)
            value_pence = int(value_pence)
            if value_pounds < 0 or value_pence < 0:
                raise Exception

            if value_pounds != None and value_pence != None:
                forms.validate(errors, '%s_value' % mode, lang.MUST_BE_GREATER_THAN_ZERO('Value'), lambda po,pe: (po+pe*100)>0, (value_pounds,value_pence))
        except:
            errors['%s_value' % mode] = lang.MUST_BE_POS_INTEGER('Pounds and pence')
            
        #Validate the reason
        forms.validate(errors, '%s_reason' % mode, lang.NO_FIELD_SUPPLIED('reason'), lambda r: bool(r), (reason,))

        #Validate and get the other user
        if other_username:
            other_user = db.users.find_one({'username':other_username})
            forms.validate(errors, '%s_username' % mode, lang.NO_CONTACT_FOUND, lambda u: bool(u), (other_user,))

        #Now do the rendering
        if not errors:
            value = round((float(value_pounds)*100 + float(value_pence)) / 100.0, 2)
            
            if mode == 'to':
                from_user, to_user = user, other_user
            else:
                from_user, to_user = other_user, user

            trans = db.transactions.save({'from_user': from_user['_id'], 'to_user': to_user['_id'], 'value':value, 'timestamp':time.time(), 'reason':reason})

            return render('transfer.html', success=True, user=self._deref_contacts(), from_user=from_user, to_user=to_user, value="%.2f" % value, mode=mode)
        else:
            return render('transfer.html', errors=errors, user=self._deref_contacts())
Example #5
0
def send_contact():
    name = request.values['name']
    email = request.values['email']
    telephone = request.values['telephone']
    is_valide, form_msg = validate(name, email, telephone)
    if is_valide == 'true':
        print(name, email, telephone)
        msg = Message(subject='testtest', sender='*****@*****.**', recipients=['*****@*****.**'])
        print('msg ok')
        msg.body = u"""Name: {}\nEmail: {}\nMessage: {}""".format(name, email, telephone)
        print('body ok')
        #mail.send(msg)
        print('sended ok')
        print(jsonify(result=is_valide, msg=form_msg).data)
        return jsonify(result=is_valide, msg=form_msg)
    else:
        return jsonify(result=is_valide, msg=form_msg)
Example #6
0
    def POST(self):
        post = web.input(_method='POST')
        errors = {}
        username = forms.get_or_add_error(post, 'username', errors, lang.NO_FIELD_SUPPLIED('username'))
        password = forms.get_or_add_error(post, 'password', errors, lang.NO_FIELD_SUPPLIED('password'))
        password_again = forms.get_or_add_error(post, 'password_again', errors, lang.NO_FIELD_SUPPLIED('password again'))

        forms.validate(errors, 'password_again', lang.PASSWORDS_DONT_MATCH, lambda p,p2: p == p2, (password, password_again))

        if username is not None:
            forms.validate(errors, 'username', lang.FIELD_MUST_BE_LEN('Username', 3), lambda u: len(u) >= 3, (username,))
            forms.validate(errors, 'username', lang.USERNAME_TAKEN, lambda u: not bool(db.users.find_one({'username':u})), (username,))
        if password is not None:
            forms.validate(errors, 'password', lang.FIELD_MUST_BE_LEN('Password', 5), lambda p: len(p) >= 5, (password,))            
            
        if errors:
			return render('register.html', errors=errors)
        else:
            users.register(username=username, password=users.pswd(password), access=0)
            web.seeother('/login/')