def store():
    try:
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']

        users = Users(name=name, email=email)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()

        msg = Message("Hello, {} welcome to Belajar Flask Python".format(name),
                      sender="*****@*****.**")
        msg.add_recipient(email)
        # msg.body = "testing"
        msg.html = render_template('mail.html',
                                   app_name="Learn Flask with Kiddy",
                                   app_contact="*****@*****.**",
                                   name=name,
                                   email=email)
        mail.send(msg)

        return response.ok('', 'Successfully create data!')

    except Exception as e:
        print(e)
Beispiel #2
0
def authenticate(nickname, password):
    from app.model.user import Users
    from manage import app
    app_id = app.config.get('WE_CHAT_APP_ID')
    secret = app.config.get('WE_CHAT_SECRET')

    content = requests.get(
        f"https://api.weixin.qq.com/sns/jscode2session"
        f"?appid={app_id}&secret={secret}&js_code={password}&grant_type=authorization_code"
    ).content
    app.logger.info(content)
    content_obj = json.loads(content)
    print(content_obj)
    if 'errcode' not in content_obj:
        # union_id = content_obj['unionid']
        open_id = content_obj['openid']
        user = Users.query.filter_by(open_id=open_id).first()
        if user is None:
            user = Users(open_id=open_id, name=nickname)
            db.session.add(user)
        else:
            user.name = nickname
        db.session.commit()
        return user
    return None
Beispiel #3
0
def store():
    try:
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']

        users = Users(name=name, email=email)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()

        return response.ok('', 'Successfully create data!')
    except Exception as e:
        print(e)
def store():
    print('OOIII')
    try:
        print('request', request.json['name'])
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']
        print('DB', db)
        users = Users(name=name, email=email)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()
        print('CEK RESPON', response)
        return response.ok('', 'Successfully create data!')

    except Exception as e:
        print(e)
def store():
    try:
        full_name = request.json['full_name']
        username = request.json['username']
        email = request.json['email']
        password = request.json['password']
        role = request.json['role']

        users = Users(full_name=full_name,
                      username=username,
                      email=email,
                      role=role)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()

        return response.ok('', 'Successfully create User!')
    except Exception as e:
        print(e)
Beispiel #6
0
    def post(self):
        try:
            name = request.json['name']
            email = request.json['email']
            password = request.json['password']

            users = Users(name=name, email=email)
            users.setPassword(password)
            db.session.add(users)
            db.session.commit()

            access_token = jwt.encode(users)
            refresh_token = jwt.encode(users, access=False)

            return response.ok({
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 'Successfully create data!')

        except Exception as e:
            return response.badRequest('', e)
def store():
    # try:
    name = request.json['name']
    email = request.json['email']
    password = request.json['password']
    role = request.json['role']
    department = request.json['department']

    users = Users(name=name, email=email, role=role, department=department)
    users.setPassword(password)
    db.session.add(users)
    db.session.commit()

    # msg = Message(f"Hello, {name} Selamat datang di Aplikasi Booking Ruang Rapat",
    #               sender="*****@*****.**")
    # msg.add_recipient(email)
    # message_value = f"Hello {name}"
    # msg.html = render_template('index.html',message_key=message_value)

    # mail.send(msg)

    return response.ok('', 'Successfully create data!')
def insert():
    try:
        # To-DO: Validate Input
        input_name = request.json['name']
        input_email = request.json['email']
        input_password = request.json['password']
    except Exception as e:
        print(e)
        return response.badRequest(
            "", Message.CONST_REQUIRED_INSERT_USER_VALIDATION)

    try:
        user = Users(name=input_name, email=input_email)
        user.setPassword(input_password)
        db.session.add(user)
        db.session.commit()

        data = singleTransform(user)
        return response.ok(data, Message.CONST_SUCCESS_INSERT_USER_MESSAGE)
    except Exception as e:
        print(e)
        return response.internalServerError()
Beispiel #9
0
def store():
    try:
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']

        users = Users(name=name, email=email)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()

        msg = Message(f"Hello, {name} welcome to Sistem Pendaftaran Proposal Online",
                      sender="*****@*****.**")
        msg.add_recipient(email)
        message_value = f"Hello, {name}"
        msg.html = render_template('email.html',message_key=message_value)

        mail.send(msg)


        return response.ok('', 'Successfully create data!')
    except Exception as e:
        print(e)
Beispiel #10
0
def store():
    try:
        name = request.json['name']
        email = request.json['email']
        password = request.json['password']

        users = Users(name=name, email=email)
        users.setPassword(password)
        db.session.add(users)
        db.session.commit()

        # msg = Message(f"Hello, {name} welcome to Belajar Flask Python",
        #               sender="*****@*****.**")
        # msg.add_recipient(email)
        # message_value = f"Hello {name}"
        # msg.html = render_template('index.html',message_key=message_value)

        # mail.send(msg)

        return response.ok('', 'Successfully create data!')

    except Exception as e:
        print(e)