コード例 #1
0
ファイル: register.py プロジェクト: MatteRubbiani/swapp
    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
コード例 #2
0
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)
コード例 #3
0
    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
コード例 #4
0
ファイル: users.py プロジェクト: baz1leus/flaskapi
 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
コード例 #5
0
    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)
コード例 #6
0
ファイル: app.py プロジェクト: lnogueir/p4Game
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'})
コード例 #7
0
    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
コード例 #8
0
 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()}
コード例 #9
0
 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
コード例 #10
0
ファイル: users.py プロジェクト: ElyaCherry/firstapi
 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
コード例 #11
0
 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]
コード例 #12
0
    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")
コード例 #13
0
    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
コード例 #14
0
    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)
コード例 #15
0
ファイル: users.py プロジェクト: DavidTbilisi/py_repo
 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
コード例 #16
0
ファイル: users.py プロジェクト: lnogueir/DetectiveBackend
 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'}
コード例 #17
0
    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
コード例 #18
0
ファイル: users.py プロジェクト: 9643kavinder/Stores-Rest-API
 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
コード例 #19
0
ファイル: users.py プロジェクト: nellaiarun/microservices
 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)
コード例 #20
0
ファイル: users.py プロジェクト: danielcrash/Api-Rest-SQL
 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
コード例 #21
0
ファイル: users.py プロジェクト: saurabhp14344/flask_restapi
    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.'}
コード例 #22
0
    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."})
コード例 #23
0
ファイル: users.py プロジェクト: ChegeBryan/Sonia_books
    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
コード例 #24
0
    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
コード例 #25
0
    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
コード例 #26
0
    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
コード例 #27
0
ファイル: register.py プロジェクト: MatteRubbiani/2b
    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
コード例 #28
0
 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
コード例 #29
0
ファイル: user_manager.py プロジェクト: Max2030/test-repo1
    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()
コード例 #30
0
ファイル: app.py プロジェクト: TWNUMBER1/foodiesvc
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