def post(self): mail=request.args.get('mail') username=request.args.get('username') password=request.args.get('password') phone=request.args.get('phoneNumber') user=UserModel.find_by_mail(mail) if user: if user.confirmed==True: return "mail already taken", 413 epsw=password.encode('utf-8') hashed_password = hashlib.sha512(epsw).hexdigest() user.username=username user.password=hashed_password user.phone_number=phone user.creation_date=time.time() user.password_change=time.time() user.save_to_db() else: now = time.time() epsw=password.encode('utf-8') hashed_password = hashlib.sha512(epsw).hexdigest() user=UserModel(mail, phone, username, hashed_password) user.save_to_db() return user.username sendmail(mail, username) return "user created, to be confirmed", 200
class TesteUserModel(TestCase): data = { "login": "******", "password": "******", "city": "Curitiba" } new_login = "******" new_password = "******" new_city = "São paulo" user_model = UserModel(**data) def test_save_user(self): self.user_model.save_user() def test_json(self): assert self.user_model.json() def test_update_user_login(self): self.user_model.update_user_login(self.new_login) def test_update_user_password(self): self.user_model.update_user_password(self.new_password) def test_update_user_city(self): self.user_model.update_user_city(self.new_city) def test_find_user(self): assert self.user_model.find_user(1)
def post(self): data = UserRegister.parser.parse_args() # Check if user name is already present if UserModel.find_by_username(data['username']): return { "message": "A user with the given username already exists" }, 403 # Check if list name is already present if TitlesModel.find_by_listname(listname=data['listname']): return { "message": "A list already exists with this name, please select a different list name." }, 403 # Check if correct admin key is supplied for admin role if data["role"] == "admin": if data["adminkey"] == None: return {"Message": "No admin code supplied for the admin"}, 401 if UserModel.check_admin_code(data["adminkey"]) == False: return {"Message": "Invalid admin code"}, 401 # Hash password before saving to DB o_hash = hashlib.new('ripemd160') o_hash.update(data["password"].encode("utf-8")) data["password"] = o_hash.hexdigest() # Save new user to DB user = UserModel(**data) user.save_to_db() return {"message": "User created successfully."}, 201
def post(self): user = UserRegisterResource.parser.parse_args() if UserModel.find_by_username(user.username): return {'message': 'user already exists'}, 409 user = UserModel(**user) user.add_user() return {'message': 'user added'}, 201
def test_create_user(self): users_model = UsersModel() user_model = UserModel() user = '******' passwd = 'fakepass' group = 'unit_test_fake_group' profile = 'unit_test_fake_profile' common_users = users_model.get_list() params = { 'name': user, 'password': passwd, 'group': group, 'profile': profile } with RollbackContext() as rollback: users_model.create(params) rollback.prependDefer(user_model.delete, user) new_users = users_model.get_list() self.assertEqual(len(new_users), len(common_users) + 1) enc_passwd = spwd.getspnam(user)[1] invalid_passwd = [None, "NP", "!", "!!", "", "LK", "*"] self.assertNotIn(enc_passwd, invalid_passwd) self.assertEqual(crypt.crypt(passwd, enc_passwd), enc_passwd)
def register(): newUser = request.get_json() if UserModel.find_by_username(newUser['username']): return {'message':'Username already exists'}, 400 user = UserModel(newUser['username'],hash_password(newUser['password'])) user.save_to_db() return jsonify({'message':'User created successfully'})
def put(self): data = UserRegister.parser.parse_args() msg = '' if data['username']: user = UserModel.find_user_details(data['username']) if user: if data['password']: user.password = data['password'] #if data['group'] : user.access = data['group'] else: user = UserModel(**data) try: user.save_to_db() except: return {'message': "Please recheck the entries."}, 400 msg += "User has been created/updated." if data['code']: priv = AccessModel.get_priviledges(data['group']) if priv: priv.access_granted = data['code'] else: priv = AccessModel(data['group'], data['code']) try: priv.add_to_db() except: return { 'message': "Please check 'group' or 'code' value." }, 400 msg += "Group has been created/updated." return {"message": msg}, 200
def post(self): data = _parser.parse_args() username = data['username'] if UserModel.find_by_username(username): return {'message': 'User already exists'}, 400 user = UserModel(username, data['password']).save() return {'success': True, 'user': user.json()}
def post(self, lobby_tag): lobby = LobbyModel.find_by_tag(lobby_tag) if not lobby: return "bleah", 432 user = UserModel(lobby_id=lobby.id) user.save_to_db() return user.id
def post(): user = UserRegisterResource.parser.parse_args() if UserModel.find_by_username(user.username): abort(409, message="User Already Exists") new_user = UserModel(**user) new_user.add_user() return {'message': f"added {new_user.username}"}, 201
def post(self): lobby = LobbyModel() lobby.save_to_db() user = UserModel(lobby_id=lobby.id) user.save_to_db() LobbyModel.erase_unused() return [lobby.tag, user.id]
def post(self): try: data = api.payload username = data['username'] email = data['email'] password = data['password'] if UserModel.check_email_exist(email): return {"status": "Email already exists"}, 400 else: hashed_password = generate_password_hash(password) user = UserModel(username=username, email=email, password=hashed_password) user.create_record() return {"status": "User added successfully"}, 201 except KeyError as e: api.abort(500, e.__doc__, status="Could not perform this action", statusCode="500") except KeyError as e: api.abort(400, e.__doc__, status="Could not perform this action", statusCode="400")
def post(cls): try: user = user_schema.load(request.get_json()) except ValidationError as err: return err.messages, 400 if UserModel.find_by_username(user['username']): return {"msg": "User Already Exists"}, 400 if UserModel.find_by_email(user['email']): return {"msg": "This email already has a registered account."}, 400 new_user = UserModel(**request.get_json()) try: new_user.register() print("User Registered...") token = generate_link_token(user['email']) UserModel.send_confirmation_email(token, user['email'], user['username']) except: return {'msg': "Error Performing Request!!"}, 500 return { 'msg': "Confirmation Link has been sent to you Email. Please Activate." }, 201
def post(self): data = parser.parse_args() username = data['username'] email = data['email'] # Checking if user already exist/created if UserModel.find_by_username(username): return {'message': f'User {username} already exists'} # create new user new_user = UserModel(username=username, password=UserModel.generate_hash( data['password']), email=email) # try: # Saving user in DB and Generating Access and Refresh token new_user.save_to_db() access_token = create_access_token(identity=username) refresh_token = create_refresh_token(identity=username) return make_response( jsonify({ 'message': f'User {username} was created', 'access_token': access_token, 'refresh_token': refresh_token }), 200)
def post(self): parsed = RegisterUser.u_prs.parse_args() u = UserModel.find_by_username(parsed.username) if u: return {"message": "Already Registered"}, 400 else: UserModel(parsed.username, parsed.password).save() return {"message": "User was added successfully"}, 200
def post(self): newUser = UserRegister.parser.parse_args() if UserModel.find_by_username(newUser['username']): return {'message': 'Username already exists'}, 400 user = UserModel(newUser['username'], hash_password(newUser['password']), newUser['email']) user.save_to_db() return {'message': 'User created successfully'}
def post(self): user_data = UserRegister.parser.parse_args() if UserModel.find_user_by_username(user_data['username']): return {"message": "A user with that username already exists"}, 400 user = UserModel(**user_data) user.save_to_db() return {"message": "User created successfully."}, 201
def post(self): data = UserRegister.parser.parse_args() row = UserModel.get_user_by_username(data['username']) if row: return {"message":"user already exist"},400 user = UserModel(**data) user.save_to_db() return {"message":"user created successfully."},201
def post(self): received_data = SignUp.parser.parse_args() if not(UserModel.getUserByName(received_data["username"]) in [None, -99]): return({'message': 'An user with that name already exists!'}, 400) newUser = UserModel(0, received_data['username'], received_data['password']) if newUser.register(): return({'message': 'User has been signed up successfully!'}, 201) else: return({'Error': 'An Error occurred while creating user {0}!'.format(received_data['username'])}, 404)
def post(self): data = attribute.parse_args() if UserModel.find_by_login(data['login']): return { "message": "Login '{}' already exists.".format(data['login']) } user = UserModel(**data) user.save_user() return {'message': 'User created successfully'}, 201
def post(self): data = UserRegister.parser.parse_args() # check user exist or not if UserModel.find_user_mapping(data['username']): return {'message': 'user already exists'}, 400 user = UserModel(**data) user.save_to_db() return {'message': 'User create successfully.'}
def post(self): data = self.parser.parse_args() if UserModel.find_by_username(data["username"]): return jsonify({"message": "User already exist in the database."}) user = UserModel(**data) user.save_to_db() return jsonify({"message": "User created successfully."})
def post(self): data = RegisterUsers.parser.parse_args() if UserModel.find_by_username(data['username']): return {"message": "username already taken"}, 400 user = UserModel(**data) user.save_to_db() return {"message": "User registered successfully"}, 201 # created
def post(self): data = _parser.parse_args() if UserModel.find_by_username(data['username']): return {'message': 'That username is already registered'}, 400 new_user = UserModel(**data) new_user.save_to_db() return {'message': 'User created successfully'}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_email(data['email']): return {"message": "User with that email already exists."}, 400 user = UserModel(**data) user.save_to_db() return {"message": "User created successfully."}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']): return {'message': 'The username entered is already taken.'}, 400 user = UserModel(**data) user.save_to_db() return {'message': 'User created successfully.'}, 201
def post(self): data = request.get_json() mail = data["mail"] username = data["username"] password = data["password"] user = UserModel.find_by_mail(mail) if user: if user.confermato == True: return "mail already taken", 400 epsw = password.encode('utf-8') hashed_password = hashlib.sha512(epsw).hexdigest() user.password = hashed_password user.username = username user.save_to_db() return "user modified" now = datetime.datetime.now() epsw = password.encode('utf-8') hashed_password = hashlib.sha512(epsw).hexdigest() user = UserModel(None, mail, username, None, None, None, 0, False, 0) user.password = hashed_password user.save_to_db() s = URLSafeTimedSerializer("password1") token = s.dumps(mail, salt="emailconfirm") #link="http://127.0.0.1:5000/confirm/"+token link = "https://seconda.herokuapp.com/confirm/" + token subject = "Conferma la tua mail su WaitingList" text = """ Ciao {}! Grazie per esserti registrato. Clicca il link qui sotto per completare la registrazione. {} Se non hai richiesto un account non preoccuparti, qualcuno si sara' confuso. Saluti, il Team WaitingList """.format(username, link) message = 'Subject: {}\n\n{}'.format(subject, text) server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login("*****@*****.**", "smartmates1") server.sendmail("smartmates2018gmail.com", mail, message) return {"message": "user created, to be confirmed"}, 200
def post(username): new_user = { 'username': username, 'password': UserRegister.parser.parse_args()['password'] } if does_user_exist(username): return abort( 404, message="user '{}' has already exist".format(username)) new_user = UserModel(**new_user) new_user.add_user() return {'new_user': new_user.json()}, 201
def put(self, name): data = UserRegister.parser.parse_args() user = UserModel.find_by_username(name) if user: user.username = data['username'] else: user = UserModel(**data) user.save_to_db() return user.json()
def createUser(): if not request.json or not 'name' in request.json: abort(400) user = { 'name': request.json['name'], 'delete_tag': 0, 'created_date': datetime.datetime.now() } user = UserModel(user) user.save_to_db() return jsonify({'user': user.name}), 201