コード例 #1
0
ファイル: app.py プロジェクト: SavchenkoDima/web-bot
def start(message):
    user_dict = {
        'first_name': message.chat.first_name,
        'username': message.chat.username,
        'last_name': message.chat.last_name,
        'user_id': message.chat.id,
    }
    keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values())
    try:
        if Users.objects.get(user_id=message.chat.id):
            user = Users.objects.get(user_id=message.chat.id)
            bot.send_message(message.chat.id,
                             text=f'Hi again {user.username}',
                             reply_markup=keyboard)
        else:
            Users(**user_dict).save()
            bot.send_message(message.chat.id,
                             text=f'Hello new buyer {message.chat.username}',
                             reply_markup=keyboard)
            user = Users.objects.get(user_id=message.chat.id)
            basket = Basket(user=user)
            basket.save()
    except Exception:
        Users(**user_dict).save()
        bot.send_message(message.chat.id,
                         text=f'Hello new buyer {message.chat.username}',
                         reply_markup=keyboard)
        user = Users.objects.get(user_id=message.chat.id)
        basket = Basket(user=user)
        basket.save()
コード例 #2
0
ファイル: instagramactions.py プロジェクト: Josrodjr/weblab08
def create_user():
  print("------------------------------------------------\n")
  print("Cantidad de Usuarios antes:", Users.objects.all().count())
  username = input("Ingrese el usuario: ")
  name = input("Ingrese el nombre: ")
  password = input("Ingrese el password: "******"Ingrese el email: ")
  introduced_user = Users(username=username, name=name, password=password, email=email)
  introduced_user.save()
  print("Cantidad de Usuarios despues:", Users.objects.all().count())
  return 1
コード例 #3
0
ファイル: create_user.py プロジェクト: Josrodjr/weblab08
    def handle(self, *args, **kwargs):
        print("Cantidad de Usuarios antes:", Users.objects.all().count())

        username = input("Ingrese el usuario: ")
        name = input("Ingrese el nombre: ")
        password = input("Ingrese el password: "******"Cantidad de Usuarios despues:", Users.objects.all().count())
コード例 #4
0
def registration():
    user_name = request.json['user_name']
    user_email = request.json['user_email']
    user_password = request.json['user_password']
    admin = False
    pw_hash = bcrypt.generate_password_hash(user_password.encode("utf-8"))

    new_user = Users(user_name, user_email, pw_hash.decode("utf-8", "ignore"), admin)
    main_db.session.add(new_user)
    main_db.session.commit()
    return user_schema.jsonify(new_user)
コード例 #5
0
    def post(self):
        login_data = Login.parser.parse_args()

        email = login_data['email']
        password = login_data['password']

        user = Users().get_user_by_email(email)

        if user:
            return {"Message": "You have succesfully logged in"}, 200
        return {"Message": "user does not exists"}, 400
コード例 #6
0
    def post(self):
        data = Sign_up.parser.parse_args()
        firstname = data['firstname']
        lastname = data['lastname']
        othernames = data['othernames']
        email = data['email']
        phoneNumber = data['phoneNumber']
        username = data['username']
        password = data['password']
        is_admin = data['is_admin']

        validate = validators.Validation()
        if not validate.validate_username(username):
            return {
                "Message":
                "username can only contain alphanumeric characters only and a minimum of 4 characters"
            }, 400
        if not validate.validate_phone_number(phoneNumber):
            return {"Message": "please put valid phone number"}, 400

        if not validate.validate_input_strings(firstname):
            return {"Message": "Please enter valid firstname"}, 400
        if not validate.validate_input_strings(lastname):
            return {"Message": "Please enter valid lastname"}, 400
        if not validate.validate_input_strings(othernames):
            return {"Message": "Please enter valid names"}, 400
        # if not validate.validate_if_is_admin(is_admin):
        #     return {"Message": "is admin must be either true or false"}, 400
        if User().get_user_by_email(email):
            return {"Message": f"A user with {email} already exists"}, 400
        if User().get_user_by_username(username):
            return {
                "Message": f"{username} already taken, please try another"
            }, 400

        user = User(firstname, lastname, othernames, email, phoneNumber,
                    username, password, bool(is_admin))
        Users.append(user)

        return {"Message": f"{user.username} created successfully"}, 201
コード例 #7
0
ファイル: root.py プロジェクト: gothaur/cinemas_project
def login():
    if request.method == "GET":
        if "user_id" in session:
            _user_id = session['user_id']
            # return render_template("login.html", user_id=session['user'])
            return render_template("login.html", user_id=_user_id, username=session["user_name"])
        else:
            return render_template("login.html")
    else:
        email = request.form.get("email")
        password = request.form.get("password")
        button = request.form.get("button_name")
        if button == "login":
            if Users.validate(connection, email, password):
                user = Users.get_user_by_email(connection, email)
                session["user_id"] = user.get_user_id()
                session["user_name"] = user.email
                flash("Zalogowano poprawnie")
                return redirect("/")
            else:
                flash("Błędny login lub hasło")
                return redirect(url_for('login'))
        if button == "register":
            user = Users(None, email, password)
            user.add_to_database(connection)
            flash("Zarejestrowano poprawnie. Zaloguj się aby kontynuować")
            return redirect(url_for("login"))
コード例 #8
0
def update_user_password(
    db: Session,
    db_user: models.Users,
    user_update: UserUpdatePassword,
    current_user: User,
):
    obj_data = jsonable_encoder(db_user)
    update_data = user_update.dict(exclude_unset=True)
    # db_user.ovpn_password = update_data["password"]
    db_user.hashed_password = get_password_hash(update_data["password"])
    db.add(db_user)
    db.commit()
    db.refresh(db_user)
コード例 #9
0
    def post(self):
        user_data = RegisterUsers.parsing.parse_args()

        firstname = user_data['firstname']
        lastname = user_data['lastname']
        username = user_data['username']
        password = user_data['password']
        email = user_data['email']

        user = Users(firstname, lastname, username, password, email)
        users.append(user)

        return {"Message": "User registration successful"}, 201
コード例 #10
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        try:
            newuser = Users(username = username,password = password)
            db.session.add(newuser)
            print('done')
            db.session.commit()
            return redirect(url_for('login'))
        except:
            return jsonify({'msg':'user already exists'})
    else:
        return render_template('register.html')
コード例 #11
0
ファイル: authentication.py プロジェクト: variable17/hwl
    def post(self):
        data = request.get_json()
        user = Users.query.filter_by(email=data['email']).first()
        if user is not None:
            return make_response(jsonify({'msg': 'email already registered'}),
                                 401)
        try:
            user = Users(email=data['email'],
                         name=data['name'],
                         password=data['password'])
        except:
            return make_response(
                jsonify({'msg': 'Looks like you forgot a value'}), 401)
        db.session.add(user)
        db.session.commit()

        return make_response(
            jsonify({'message': 'New user created, please login!'}), 201)
コード例 #12
0
ファイル: auth.py プロジェクト: Oper18/test_pitch
async def register_user(
        reg: Register,
        response: Response,
        authorization: Optional[str] = Header(None),
        status_code: Optional[Any] = status.HTTP_200_OK,
) -> dict:
    salt = uuid.uuid4().hex
    async with get_session() as s:
        user = Users(
            username=reg.username,
            salt=salt,
            password=password_hash(
                password=reg.password,
                salt=salt
            ),
        )
        s.add(user)
        await s.commit()
    return RegisterResponse.parse_obj(
        {"username": reg.username, "password": reg.password}
    )
コード例 #13
0
	def register(self, email, name, password):
		db.add(Users(user_email=email, user_name=name, user_password=password))
		db.commit()