コード例 #1
0
def user_login(n_clicks, username_or_email, password):
    if n_clicks:
        user_username = Users.get_or_none(Users.username == username_or_email)
        user_email = Users.get_or_none(Users.email == username_or_email)
        users = [user_username, user_email]
        for user in users:
            if user is not None:
                flag_password = check_password(raw_password=password,
                                               enc_password=user.password)
                if flag_password:
                    login_user(user=user)
                    return '/home', ''
        return no_update, failure_alert
コード例 #2
0
def profile_save_changes(n_clicks, username, password, confirm):
    if n_clicks:
        email = current_user.email
        data_changes = []
        if username != current_user.username:
            data_changes.append('Username changed.')
            Users().change_user(username=username, email=email)
        if Users().set_password(password) != current_user.password:
            data_changes.append('Password changed.')
            Users().change_password(password=password, email=email)
        if data_changes:
            data_changes.append('Changes saved successfully.')
            text_alert = ' '.join(data_changes)
            return 1, [dbc.Alert(text_alert, color='success')]
コード例 #3
0
ファイル: oauth.py プロジェクト: skarzi/mapa_huncwotow
 def get(self):
     app_hash = request.args['hash']
     user = Users.get_or_create(app_hash=app_hash)
     if user.is_authorized():
         return {"success": True}
     else:
         return {"success": False, "url": self.get_oauth_url(app_hash)}
コード例 #4
0
 def get(self):
     app_hash = request.args['hash']
     user = Users.get_or_create(app_hash=app_hash)
     response = user.get_classes()
     if response:
         first_classes = response[0]
         date, time = first_classes["start_time"].split()
         time = time[:-3]
         return {
             "name": first_classes["name"]["pl"],
             "room": first_classes["room_number"],
             "time": time
         }
     else:
         return {}, 404
コード例 #5
0
 def __checking_username(self):
     username = self.input_params['username']
     if username:
         if current_user.is_authenticated and username == current_user.username:
             self.__generate_success_formtext_with_color(
                 field_name='username', formtext='Username is good')
         elif Users().get_or_none(Users.username == username):
             self.__generate_danger_formtext_with_color(
                 field_name='username', formtext='Username already exists')
         else:
             self.__generate_success_formtext_with_color(
                 field_name='username', formtext='Username is good')
     else:
         self.__generate_danger_formtext_with_color(
             field_name='username', formtext='Username must not empty')
コード例 #6
0
 def __checking_email(self):
     email = self.input_params['email']
     if email:
         validate_flag = validate_email(email)
         if Users().get_or_none(Users.email == email):
             self.__generate_danger_formtext_with_color(
                 field_name='email', formtext='Email already exists')
         elif validate_flag:
             self.__generate_success_formtext_with_color(
                 field_name='email', formtext='Email is good')
         else:
             self.__generate_danger_formtext_with_color(
                 field_name='email', formtext='Email is not valid')
     else:
         self.__generate_danger_formtext_with_color(
             field_name='email', formtext='Email must not empty')
コード例 #7
0
def register():
    data = request.get_json()
    print("DATA", data)
    if (data == None):
        return jsonify({
            'status':
            'error',
            'message':
            "Make sure all form fields have been filled out"
        }), 400
    duplicate = db.session.query(Users).filter(
        Users.username == data.get('username')).first()
    if (data.get('confirmPassword') != data.get('password')):
        return jsonify({
            'status': 'error',
            'message': "Passwords dont match"
        }), 400

    if (duplicate):
        return jsonify({
            'status': 'error',
            'message': "Username already exists"
        }), 400

    if (data.get('email') and data.get('username') and data.get('password')):
        user = Users(email=data.get('email'), username=data.get('username'))
        db.session.add(user)
        db.session.commit()
        login = Login(password=data.get('password'),
                      parent_id=user.id,
                      parent_username=user.username)
        db.session.add(login)
        db.session.commit()
        return jsonify({'id': user.id, 'username': user.username}), 201

    else:
        return jsonify({
            'status': 'error',
            'message': "Missing form fields"
        }), 400
コード例 #8
0
ファイル: views.py プロジェクト: Li-rr/to_be_an_artist_web
def logon(request):
    if request.method == "POST":
        print('f**k you')

        postBody = request.body
        json_result = json.loads(postBody)
        username = json_result['username']
        password = json_result['passward']

        print("=>", username, password)
        print('=>', postBody)
        print('=>', request.POST)
        user = Users.objects.filter(username=username)
        if user:
            print("用户已存在")
            return HttpResponse("用户名已存在")
        else:
            # 创建用户
            new_user = Users()
            new_user.username = username
            new_user.passward = password
            new_user.save()
            return HttpResponse("注册成功")
コード例 #9
0
def load_user(user_id: int):
    return Users.get(Users.id == user_id)
コード例 #10
0
def insert(request):
    """执行添加"""
    try:
        ob = Users()  # 实例化Users模型
        ob.username = request.POST['registerUsername']

        # 密码md5加密
        m = hashlib.md5()
        m.update(bytes(request.POST['registerPassword'], encoding='utf-8'))
        ob.password = m.hexdigest()

        ob.sex = request.POST['gender']
        ob.name = request.POST['registerName']
        ob.email = request.POST['registerEmail']
        ob.phone = request.POST['registerPhone']
        ob.address = request.POST['registerAddress']
        ob.code = request.POST['registerZip']
        ob.state = 1
        ob.addtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        ob.save()  # 将数据存储至数据库
        return redirect('/backend/users')
    except Exception as err:
        print(err)
        context = {'Info': 'Addition Failed', 'Detail': err}
        return render(request, 'backend/info.html', context)
コード例 #11
0
try:
    from backend.main import Worker
    from backend.models import Users
except ImportError:
    exit('copy settings.py.default->settings.py and '
         'set TOKEN, TOKEN_MAP and SECRET_KEY_SERVER')


if __name__ == '__main__':
    u = Users()
    if not u.check_exists_admin_user:
        u.insert_default_values()
    t = Worker()
    t.run(delta_days=1)
コード例 #12
0
def registrations_success(n_clicks, username, email, password):
    if n_clicks:
        if Users().add_user(username=username, email=email, password=password):
            login_user(user=Users.get(Users.username == username))
            return ['/home']