Example #1
0
def register():
    print(request.json)
    wallet_data = request.json
    password_hashed = HMAC(b"somesecret",
                           str.encode(wallet_data['password'])).digest()
    wallet_data['password'] = password_hashed
    wallet = Wallet(**wallet_data)
    wallet.save()
    return make_response(
        (app.json_encoder().encode(wallet.get_sanitized_object()), "201"))
Example #2
0
    def CreateWallet(self,  name):
        log.info('CreateWallet(' + name + ')...')
            
        try:
            Wallet.objects.get(name=name)
            log.info('Name %s already exists. Aborting creation ', name)
            return tools.HttpHelper.BuildBadRequest('The wallet %s already exists.' % (name))

        except DoesNotExist:
            # Not found
            pass
            
        #except Exception as e:
         #   log.error('Exception: ' + str(e))
          #  return tools.HttpHelper.BuildBadRequest('Exception: ' + str(e))
            
            
        # create wallet
        wallet = Wallet(name=name,  balance=0)
        wallet.save()
                
        return tools.HttpHelper.BuildGoodRequest('CreateWallet created') 
Example #3
0
 def post(self):
     username = request.json['username']
     email = request.json['email']
     password = request.json['password']
     # email regexp validation
     if not re.match(r'^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$',
                     email):
         abort(400, message='Email not valid.')
     # verify password weakness
     if len(password) < 6:
         abort(400, message='Password too weak.')
     else:
         try:
             user = User(username=username,
                         email=email,
                         password=generate_password_hash(password),
                         active=False)
             user.save()
         # verify if email/username already exist
         except NotUniqueError:
             abort(400,
                   message='Username or email already used by another user')
     # encode jwt
     exp = datetime.datetime.utcnow() + datetime.timedelta(
         days=ACTIVATION_EXPIRE_DAYS)
     encoded = jwt.encode({
         'email': email,
         'exp': exp
     },
                          SECRET_KEY,
                          algorithm='HS256')
     activation_code = encoded.decode('utf-8')
     # Send activation email
     activation_str = "Your activation code is: " + activation_code
     send_email(email, "Activation code", activation_str)
     # create new wallet
     wallet = Wallet(username=username)
     wallet.save()
     return {'success': "Account created"}