def GET(self, username): # auth? try: users = model.Users(username=username) user = users.list()[0] except: context = Storage(title=_("No such user")) print render.collections(context, []) return topics_subs = model.Projects(by_user_role=(user, "subscribed")) # topics_subs.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE) # topics_subs.annotate_by_points() # topics_subs.annotate_by_comments() topics_highlighted = model.Projects( tags=model.Tags("official:highlighted")) # topics_highlighted.annotate_by_profiles(default=DEFAULT_TOPIC_PROFILE) # topics_highlighted.annotate_by_latest_points() # topics_highlighted.annotate_by_comments() topics_subs.add(topics_highlighted) topics_subs.sort_by_title() context = Storage(title=_("User") + " " + username, ) web.header("content-type", feed_content_type['atomserv']) print render.collections(context, topics_subs)
def authenticate(credentials): """ input: credentials output: user or None """ # look up identity service identity_service = _get_identity_service(credentials) # try to authenticate with the identity service auth_result = identity_service.authenticate(credentials) if not auth_result: return None # drop password as it is not needed any more credentials.password = auth_result.credentials = auth_result.password = None # check if corresponding internal user exists iuser = internalusers.check_user(credentials) if iuser: # if it exists, just give it return iuser # make internal user corresponding to external one group = model.Groups(auth_result.group_name).list()[0] user = internalusers.add_user(auth_result, auth_result.profile, group=group) users = model.Users(username=auth_result.username) return users.list()[0]
def new_user(u_name, db: Session = Depends(get_db)): db_user = model.Users(user_name=u_name) db.add(db_user) db.commit() db.refresh(db_user) return db_user
def signUp(): _username = request.form['login'] _email = request.form['email'] _password = request.form['password'] if not validateUsername(_username): return render_template( "message.html", messageContent= "Podana nazwa użytkownika jest niewłaściwa. Nazwa może składać się z liter, cyfr oraz znaków kropki i podkreślnika." ) if not validateEmail(_email): return render_template('message.html', messageContent="Adres email jest niepoprawny") _hashedPassword = hash_password(_password) delay() username_taken = model.Users.query.filter_by(username=_username).first() if username_taken: return render_template( 'message.html', messageContent="Nazwa użytkownika jest już zajęta") emial_taken = model.Users.query.filter_by(email=_email).first() if emial_taken: return render_template('message.html', messageContent="Adres email jest już w użyciu") new_user = model.Users(username=_username, email=_email, password=_hashedPassword) db.session.add(new_user) db.session.commit() activation_token_parts = { 'username': _username, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=5) } activation_token = str( jwt.encode(activation_token_parts, app.config['SECRET_KEY']))[2:-1] activation_link = 'http://127.0.0.1:5000/activateAccount/' + activation_token msg = "Link aktywacyjny (ważny przez 5 minut): " + activation_link send_mail('Aktywacja konta', msg, _email) return render_template( 'message.html', messageContent= "Na podany adres została wysłana wiadomość zawierająca link aktywacyjny. Zalogowanie będzie możliwe dopiero po aktywowaniu konta." )
def get_user(): if "current_user" in web.ctx: return web.ctx.current_user session = session_manager.session() if "user_id" in session and session.user_id: users = model.Users(id=session.user_id) users.annotate_by_groups() try: web.ctx.current_user = user = users.list()[0] return user except: pass del users
def do_register_post(): params = get_required_params("POST", ['login', 'passwd', 'solve']) good_sum = flask.session.get(K_CAPTCHA, -1) if CAPTCHA_ENABLED and params['solve'] != good_sum: add_msg('U fail at math ;-(') n = sql_session.query(model.Users).filter_by(username=params.get('login')).count() if n > 0: add_msg("User already exists !") return do_render() user = model.Users( username=params.get('login'), password=backend.password_hash(params.get('passwd')), motd="", ) sql_session.add(user) sql_session.commit() backend.setup_user(params.get('login')) add_msg("User created ! login now !") return do_render()
def add(): # 创建user的时候,id自增长,不用赋值 # 给其他属性赋值 user1 = model.Users(name='ls2',age=12,sex=False) user2 = model.Users(name='ls3',age=12,sex=False) user3 = model.Users(name='ls4',age=12,sex=False) user4 = model.Users(name='ls5',age=12,sex=False) user5 = model.Users(name='ls6',age=12,sex=False) user6 = model.Users(name='ls7',age=12,sex=False) # db.session 数据库回话对象,用来对数据库增删改查 # db.session.add(user) db.session.add_all([user1,user2,user3,user4,user5,user6]) # 增删改之后需要提交一下 db.session.commit() return 'add success'
def create_user(db: Session, user: schemas.UserCreate): """Creates a user""" # Creates a Fake hashed password hashed_password = user.password + "thisisaplaceholder" # Creates a user db_user = model.Users( fname=user.fname, lname=user.lname, address=user.address, city=user.city, zip_code=user.zip_code, phone=user.phone, email=user.email, password=hashed_password, app_date=user.app_date, # co_app_fname=user.co_app_fname, # co_app_lname=user.co_app_lname, # co_app_email=user.co_app_email, pref_communication=user.pref_communication, print_permissions=user.print_permissions, member_type=user.member_type, member_standing=user.member_standing, other_orgs=user.other_orgs, num_of_gsd=user.num_of_gsd, num_breedings=user.num_breedings) # Adds user to the database session db.add(db_user) # Commits user to the database db.commit() # Refreshes the database instances db.refresh(db_user) return db_user
def user_registration_and_verification(): """Валидация формы регистрации пользователя""" if request.method == "POST": try: username = request.form['username'] if len(username) > 4 \ and len(request.form['password0']) > 4 \ and request.form['password0'] == request.form['password']: symbols_and_username_result = search_bad_symbols_and_username( username) if symbols_and_username_result != 'No': flash(symbols_and_username_result, 'danger') else: search_user_result = user_verification_on_the_server( username, request.form['email']) if not search_user_result: # если username и email уникальные hash_ = hashlib.md5( request.form['password0'].encode()).hexdigest() res = model.Users(username=username, email=request.form['email'], password_hash=hash_) result_registration = model.add_object_to_base(res) if result_registration is not None: # если запись в БД не успешная flash('Ошибка при регистрации', 'danger') else: user_id = model.Users.query.with_entities( model.Users.id).filter_by( username=username).first() create_profile = model.Profiles(user_id=user_id) result_create_profile = model.add_object_to_base( create_profile) if result_create_profile is not None: # если запись в БД не успешная flash('Ошибка при регистрации', 'danger') else: os.mkdir(f'static/users/{username.lower()}') os.mkdir( f'static/users/{username.lower()}/graph') os.mkdir( f'static/users/{username.lower()}/profile') flash('Вы успешно зарегистрированы', category='success') return True else: flash(f'Запись ({search_user_result}) уже есть в базе', category='danger') else: flash('Ошибка ввода данных', 'danger') except TypeError: flash( 'Unicode-объекты должны быть закодированы перед хешированием', 'danger') except ValueError: flash('Не верный тип данных', 'danger') except FileExistsError: flash('Папка пользователя была создана ранее', 'danger')
def address(): user = model.Users(name='ww',age=30,sex=False,address='henana') db.session.add(user) db.session.commit() return 'address............'