Beispiel #1
0
 def POST_password(self, uid):
     user = db.select('users',
                      what='password',
                      where='id=$uid',
                      vars=locals())[0]
     form = get_password_form(user)
     set_passwd_form = 'curr_password' not in [
         inp.name for inp in list(form.inputs)
     ]
     i = web.input()
     if form.validates(i):
         if set_passwd_form or auth.check_password(user, i.curr_password):
             enc_password = auth.encrypt_password(i.password)
             db.update('users',
                       password=enc_password,
                       verified=True,
                       where='id=$uid',
                       vars=locals())
             helpers.set_msg('Password %s.' %
                             ('saved' if set_passwd_form else 'changed'))
             raise web.seeother('/%s/preferences' % uid)
         else:
             helpers.set_msg('Invalid Password', 'error')
             form.note = 'Current Password invalid.'
             form.valid = False
     return self.GET(uid, password_form=form)
Beispiel #2
0
    def POST(self):
        """
        Posted data has three keys:
            'username', 'email', 'password'
        """
        data = web.input()

        email = data['email']
        email_validate = auth.validate_email(email)
        if not email_validate:
            return views.layout.register(info='email can not be validate')
        email_exist = wtdata.email_exist(email)
        if email_exist:
            return views.layout.register(info='email exist')

        pwd = data['password']
        hashed_pwd = auth.encrypt_password(pwd)
        print(hashed_pwd)

        user_info = {}
        user_info['username'] = data['username']
        user_info['password'] = hashed_pwd
        user_info['email'] = email
        user_id = wtdata.add_user(user_info)
        wtdata.add_default_category(user_id)

        return web.seeother('/login')
    def post(self):
        username, password = extract_credentials(self.json_request)

        while True:
            got_it = yield tornado.gen.Task(self.signup_lock.acquire, blocking=True)
            if got_it:
                break
            else:
                yield gen.sleep(10)

        inserted = yield tornado.gen.Task(
            self.redis_conn.setnx,
            username,
            auth.encrypt_password(password)
        )

        if inserted == 0:
            raise tornado.web.HTTPError(409, 'Such a username already exists')

        yield gen.Task(self.signup_lock.release)

        self.reply({
            'status': 'ok',
            'token': auth.generate_token(username).decode('ascii')
        }, status_code=201)
Beispiel #4
0
def register():
    try:
        user = User(name=request.json.get('name'),
                    email=request.json.get('email'),
                    password=auth.encrypt_password(
                        request.json.get('password')))
        user.save()

        return jsonify({'user': user})
    except:
        return jsonify({'msg': 'Email already taken'}), 500
Beispiel #5
0
 def POST_password(self, uid):
     user = db.select('users', what='password', where='id=$uid', vars=locals())[0]
     form = get_password_form(user)
     i = web.input()
     if form.validates(i):
         if ('curr_password' not in form) or auth.check_password(user, i.curr_password):
             enc_password = auth.encrypt_password(i.password)
             db.update('users', password=enc_password, verified=True, where='id=$uid', vars=locals())
             helpers.set_msg('Password saved.')
         else:
             helpers.set_msg('Invalid Password', 'error')    
         raise web.seeother('/%s' % uid)
     else:
          return self.GET(uid, password_form=form)   
Beispiel #6
0
def registrar_usuario_logica(
    email_usuario, senha_usuario, presenter
) -> UserRegistrationResponse:  #indico o tipo de retorno que essa função vai ter
    encrypted_password = auth.encrypt_password(senha_usuario)
    repository = UserRepostory()

    user_already_registered = repository.get_encrypt_password(email_usuario)

    if user_already_registered:

        return presenter(False)
    else:
        registered = repository.insert_user(email_usuario, encrypted_password)
        return presenter(
            True, *registered.values()
        )  #retorno todos os dados de registro desmembrados para a respectiva função do presenter .values retorna apenas os valores do json
Beispiel #7
0
 def POST_password(self, uid):
     user = db.select('users', what='password', where='id=$uid', vars=locals())[0]
     form = get_password_form(user)
     set_passwd_form = 'curr_password' not in [inp.name for inp in list(form.inputs)]
     i = web.input()
     if form.validates(i):
         if set_passwd_form or auth.check_password(user, i.curr_password):
             enc_password = auth.encrypt_password(i.password)
             db.update('users', password=enc_password, verified=True, where='id=$uid', vars=locals())
             helpers.set_msg('Password %s.' % ('saved' if set_passwd_form else 'changed'))
             raise web.seeother('/%s/preferences' % uid)
         else:
             helpers.set_msg('Invalid Password', 'error')    
             form.note = 'Current Password invalid.'
             form.valid = False
     return self.GET(uid, password_form=form)   
Beispiel #8
0
 def POST_password(self, uid):
     user = db.select("users", what="password", where="id=$uid", vars=locals())[0]
     form = get_password_form(user)
     set_passwd_form = "curr_password" not in [inp.name for inp in list(form.inputs)]
     i = web.input()
     if form.validates(i):
         if set_passwd_form or auth.check_password(user, i.curr_password):
             enc_password = auth.encrypt_password(i.password)
             db.update("users", password=enc_password, verified=True, where="id=$uid", vars=locals())
             helpers.set_msg("Password %s." % ("saved" if set_passwd_form else "changed"))
             raise web.seeother("/%s/preferences" % uid)
         else:
             helpers.set_msg("Invalid Password", "error")
             form.note = "Current Password invalid."
             form.valid = False
     return self.GET(uid, password_form=form)
    def post(self):
        username, password = extract_credentials(self.json_request)

        stored_password = yield tornado.gen.Task(
            self.redis_conn.get,
            username
        )

        if (
            stored_password is not None and
            stored_password == auth.encrypt_password(password)
        ):
            self.reply({
                'status': 'ok',
                'token': auth.generate_token(username).decode('ascii')
            })
        else:
            raise tornado.web.HTTPError(401, 'Wrong password')
Beispiel #10
0
def register():
    try:

        user = User(id_number=request.form['id_number'],
                    nit_driving_school=request.form['nit_driving_school'],
                    name=request.form['name'],
                    last_name=request.form['last_name'],
                    email=request.form['email'],
                    password=auth.encrypt_password(request.form['password']),
                    is_admin=request.form['is_admin'])

        user.save()

        return jsonify({'user': user}), 200

    except:

        return jsonify({'msg': 'No se ha podido registrar el usuario.'}), 500