def put(self, credential): username = get_jwt_identity() data = request.get_json() current_user_model = UserModel.find_by_username(username) if credential == 'email': current_user_model.email = data[credential] current_user_model.add_commit_data() return { "message": "Your {0} was changed to {1}.".format(credential, data[credential]) } elif credential == 'firstname': current_user_model.firstname = data[credential] current_user_model.add_commit_data() return { "message": "Your {0} was changed to {1}.".format(credential, data[credential]) } elif credential == "lastname": current_user_model.lastname = data[credential] current_user_model.add_commit_data() return { "message": "Your {0} was changed to {1}.".format(credential, data[credential]) } else: return {"message": "No changes were made."}
def post(self): parser = reqparse.RequestParser() parser.add_argument('username', help='This field cannot be blank', required=True) parser.add_argument('password', help='This field cannot be blank', required=True) data = parser.parse_args() current_user = UserModel.find_by_username(data['username']) if not current_user: return { 'message': 'User {} doesn\'t exist'.format(data['username']) } if UserModel.verify_hash(data['password'], current_user.password): access_token = create_access_token(identity=data['username']) refresh_token = create_refresh_token(identity=data['username']) return { 'message': 'Logged in as {}'.format(current_user.username), 'access_token': access_token, 'refresh_token': refresh_token } else: return {'message': 'Wrong credentials'}
def get(self): username = get_jwt_identity() current_user = UserModel.find_by_username(username) return { "username": current_user.username, "email": current_user.email, "firstname": current_user.firstname, "lastname": current_user.lastname, }
def get(self): username = get_jwt_identity() current_user = UserModel.find_by_username(username) if current_user.confirmed: return {"message": "Your account has been already verified."} else: mailTo(username=username, email=current_user.email, template="userconfirmation.html") return {"message": "Confirmation email sent."}
def get(self, token): decoded = decode_token(token) times = datetime msg = '' if int(times.datetime.now().timestamp()) > decoded["exp"]: msg = "The confirmation link has expired" else: current_user_model = UserModel.find_by_username(username) current_user_model.confirmed = True username = current_user_model.username current_user_model.save_to_db() msg = "Your account has been verified!" return {"msg": msg}
def get(self, credential): username = get_jwt_identity() current_user = UserModel.find_by_username(username) answer = '' if credential == 'email': answer = current_user.email elif credential == 'firstname': answer = current_user.firstname elif credential == "lastname": answer = current_user.lastname if answer: return {credential: answer} else: return {"message": "There is no such parameter"}
def get(self, id): current_user = get_jwt_identity() current_user_model = UserModel.find_by_username(current_user) porto = current_user_model.portfolios[id - 1] return { "name": porto.name, "portfolio": porto.portfolio, "start": porto.start, "end": porto.end, "roi": porto.roi, "profit": porto.profit, "coins": porto.cryptocurrencies, "weights": porto.weights, "made": porto.made_on }
def delete(self, id): #parser.add_argument('portfolio', help = 'This field cannot be blank', required = True) #data = parser.parse_args() data = request.get_json(silent=True) delete_name = data['portfolio'] current_user = get_jwt_identity() current_user_model = UserModel.find_by_username(current_user) portoId = current_user_model.portfolios[id - 1].id print(id) print(portoId) current_user_model.delete_portfolio(current_user_model.portfolios[id - 1]) return { "message": "{}'s Porfolio {} was deleted!".format(current_user, delete_name) }
def put(self, id): #parser.add_argument('portfolio', help = 'This field cannot be blank', required = True) #data = parser.parse_args() data = request.get_json(silent=True) new_name = data['portfolio'] current_user = get_jwt_identity() current_user_model = UserModel.find_by_username(current_user) new_portfolio = PorfolioModel(name=new_name) old_name = current_user_model.portfolios[id + 1].name current_user_model.portfolios[id + 1] = new_portfolio current_user_model.add_data() new_portfolio.add_data() new_portfolio.commit() return { "message": "Portfolio {} has been changed to {}".format(old_name, new_name) }
def get(self): parser = reqparse.RequestParser() current_user = get_jwt_identity() current_user_model = UserModel.find_by_username(current_user) porto = [] for i in current_user_model.portfolios: porto.append({ "name": i.name, "portfolio": i.portfolio, "profit": i.profit, "roi": i.roi, "start": i.start, "end": i.end, "coins": i.cryptocurrencies, "weights": i.weights, "saved": str(int(i.made_on.timestamp() * 1000)) }) return {"user": current_user, "portfolios": porto}
def put(self): parser = reqparse.RequestParser() parser.add_argument('password', help='This field cannot be blank', required=True) parser.add_argument("newpassword", help='This argument cannot be blank', required=True) username = get_jwt_identity() current_user = UserModel.find_by_username(username) data = parser.parse_args() if UserModel.verify_hash(data['password'], current_user.password): current_user.password = UserModel.generate_hash( data['newpassword']) current_user.add_commit_data() return {'message': 'Your password was updated successfully!'} else: return {"message": 'Wrong password'}
def post(self): #try: current_user = get_jwt_identity() current_user_model = UserModel.find_by_username(current_user) #if not current_user_model.confirmed: # return {"message":"Your account is not verifyied"} data = request.get_json() name = data['name'] if name == '': return {"message": "You must specify a name of Your porfolio"} start = data['start'] end = data['end'] roi = float(data['roi']) profit = float(data['profit']) portfolio = data['portfolio'] coinSequence = data['coins'] coinWeights = '' coinlist = '' for key, value in coinSequence.items(): coinWeights += str(value) + ',' coinlist += key + ',' for por in current_user_model.portfolios: if (por.name == name): return { "message": 'Portfolio with name "{}" already exists.'.format(name) } break new_portfolio = PortfolioModel(name=name, portfolio=portfolio, start=start, end=end, cryptocurrencies=coinlist, weights=coinWeights, profit=profit, roi=roi) current_user_model.add_portfolio(new_portfolio) new_portfolio.add_data() current_user_model.add_data() new_portfolio.commit() return {"message": "{0} created {1}".format(current_user, name)}
def post(self): parser = reqparse.RequestParser() parser.add_argument('username', help='This field cannot be blank', required=True) parser.add_argument('password', help='This field cannot be blank', required=True) parser.add_argument('email') data = parser.parse_args() if UserModel.find_by_username(data['username']): return { 'message': 'User {} already exists'.format(data['username']) } if UserModel.find_by_email(data['email']): return { 'message': 'An user with email "{}" already exists'.format(data['email']) } new_user = UserModel(username=data['username'], password=UserModel.generate_hash( data['password']), email=data['email']) try: new_user.save_to_db() #access_token = create_access_token(identity = data['username']) #refresh_token = create_refresh_token(identity = data['username']) mailTo(username=data['username'], email=data['email'], template="userconfirmation.html") return { 'message': 'User {} was created, please check your email for varification' .format(data['username']), #'access_token': access_token, #'refresh_token': refresh_token, } except: return {'message': 'Something went wrong'}, 500