def setUp(self): db.create_all() idea1 = Idea("This is a test note", complete=False, user_id=1) idea2 = Idea("This is another test note", complete=False, user_id=1) idea3 = Idea("This is a Kirby test note", complete=False, user_id=2) pusheen = User('pusheen', 'test123') kirby = User('kirby', 'test321') db.session.add_all([idea1, idea2, idea3, pusheen, kirby]) db.session.commit()
def login_judge(): if request.form['password'] == '123' and request.form['id'] == 'qwe': user = User() login_user(user) return redirect('/upload') else: flash('用户名或密码错误!') return render_template('login.html')
def add_user(name, surname, team, phone, date): new_user = User(name=name, surname=surname, team=team, phone=phone, date=date) session.add(new_user) session.commit()
def login(provider): #STEP 1 - Parse the auth code auth_code = request.json.get('auth_code') if provider == 'google': try: oauth_flow = flow_from_clientsecrets('client_secrets.json', scope='') oauth_flow.redirect_uri = 'postmessage' credentials = oauth_flow.step2_exchange(auth_code) except FlowExchangeError: response = make_response(json.dumps('Failed to upgrade the authorization code.'), 401) response.headers['Content-Type'] = 'application/json' return response # Check that the access token is valid. access_token = credentials.access_token url = ('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s' % access_token) h = httplib2.Http() result = json.loads(h.request(url, 'GET')[1]) # If there was an error in the access token info, abort. if result.get('error') is not None: response = make_response(json.dumps(result.get('error')), 500) response.headers['Content-Type'] = 'application/json' #STEP 3 - Find User or make a new one #Get user info h = httplib2.Http() userinfo_url = "https://www.googleapis.com/oauth2/v1/userinfo" params = {'access_token': credentials.access_token, 'alt':'json'} answer = requests.get(userinfo_url, params=params) data = answer.json() picture = data['picture'] email = data['email'] #see if user exists, if it doesn't make a new one user = session.query(User).filter_by(email = email).first() if not user: user = User(picture = picture, email = email) session.add(user) session.commit() #STEP 4 - Make token token = user.generate_auth_token(600) #STEP 5 - Send back token to the client return jsonify({'token': token.decode('ascii')}) #return jsonify({'token': token.decode('ascii'), 'duration': 600}) else: return 'Unrecoginized Provider'
def _read_account_file(self): with open(self._file_path, 'r') as file: for file_line in file.readlines(): _, mail, username, region = file_line.strip().split(' ') user = User() user.Username = username user.Password = self._common_password user.Mail = mail user.Region = region yield user
def post(self): """ POST method for the /signup action. Validates the inputs and redirects the user to the welcome page if validations are ok. If not, render the signup page, keeping the username and email values, and show error messages. """ input_username = self.request.get("username") input_password = self.request.get("password") input_verify = self.request.get("verify") input_email = self.request.get("email") params = dict(username=input_username, email=input_email) valid_username = verify_username(input_username) valid_password = verify_password(input_password) valid_email = verify_email(input_email) match = verify_match(input_password, input_verify) error = False if not valid_username: params["invalid_username"] = "******" error = True else: if User.by_name(input_username): params["invalid_username"] = "******" error = True if not valid_password: params["invalid_password"] = "******" error = True if not match: params["not_match"] = "Your password didn't match." error = True if not valid_email: params["invalid_email"] = "That's not a valid email." error = True if error: self.render("signup.html", **params) else: encrypted_password = utils.make_pw_hash(input_username, input_password) user = User(username=input_username, pw_hash=encrypted_password, email=input_email) user.put() self.set_secure_cookie("user_id", str(user.key().id())) self.redirect("/welcome")
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): password = generate_password_hash(form.password.data, method='sha256') new_user = User(form.name.data, form.username.data, form.email.data, password) db.session.add(new_user) db.session.commit() return redirect(url_for('index')) else: return render_template('register.html', form=form)
def signup(): form = UserForm(request.form) if request.method == "POST" and form.validate(): try: new_user = User(form.data['username'], form.data['password']) db.session.add(new_user) db.session.commit() except IntegrityError as e: flash("Oopsy! Please try again!") return render_template('users/signup.html', form=form) return redirect(url_for('login')) return render_template('users/signup.html', form=form)
def get_user_from_db_for_username(self): value = """"%s""" "" % self.username() results = self.sql_interface.select_all_single_target( type='*', table=self.users_table, target_column='username', target_value=value) print 'results' + str(results) user = User() user.from_db_data(results) print str(user) return user
def post(self): update_password_data = request.get_json() try: username = update_password_data['username'] old_password = update_password_data['old_password'] new_password = update_password_data['new_password'] except Exception as e: print(str(e)) abort(503) user = User(username, old_password) flag, msg = user.user_update_password(new_password) error_code = 0 if flag else 1 result = make_response(jsonify({'msg': msg, 'error_code': error_code})) return result
def signup(username, password, conf_password, user_category='normal'): if password.strip() == '' or username.strip() == '': return 'username or password cannot be empty' if not password == conf_password: return 'passwords provided do not match' # check whether user exists user_exists = [user for user in users if user['username'] == username] if len(user_exists) > 0: return 'user already exists' else: # create a user now and add him/her to the in-memory database user_object = User(username, password, user_category) users.append(user_object.__dict__) return 'Account created successfully'
def new_user(): email_u = request.json.get('email') password = request.json.get('password') picture = request.json.get('picture') if email_u is None or password is None: print "missing arguments" return jsonify(), 400 if session.query(User).filter_by(email = email_u).first() is not None: print "existing user" user = session.query(User).filter_by(email = email_u).first() return jsonify({'message':'user already exists'}), 200 user = User(email = email_u) user.hash_password(password) session.add(user) session.commit() return jsonify({ 'username': user.email}), 201
def signup(): form = SignupForm() if request.method == 'GET': return render_template('signup.html', form=form) elif request.method == 'POST': if form.validate_on_submit(): if User.query.filter_by(username=form.username.data).first(): flash("This username already exists", "warning") return redirect(url_for('signup')) else: newuser = User(form.username.data, form.password.data) userdb.session.add(newuser) userdb.session.commit() flash("User created!!!", "success") return redirect(url_for('login')) else: flash("Form didn't validate", "danger") return redirect(url_for('signup'))
def post(self): register_data = request.get_json() try: username = register_data['username'] password = register_data['password'] except Exception as e: print(str(e)) abort(503) new_user = User(username, password) flag, msg = new_user.user_register() error_code = 0 if flag else 1 result = make_response( jsonify({ 'status': flag, 'msg': msg, 'error_code': error_code })) return result
def signup_post(): email = request.form.get('email') name = request.form.get('name') password = request.form.get('password') user = User.query.filter_by(email=email).first() if user: flash('Email address already exists') return redirect(url_for('signup')) new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256')) userdb.session.add(new_user) userdb.session.commit() os.mkdir("videos/{}/Stories".format(new_user.id)) os.mkdir(os.path.join("videos/{}".format(new_user.id), "Other Videos")) return redirect(url_for('login'))
''' Purpose: commit session in database file ''' from connection import Session, engine, Base from user_model import User, Address # generate database schema Base.metadata.create_all(engine) # create a new session session = Session() # session.add_all([ # User(name='wendy', fullname='Wendy Williams', nickname='windy'), # User(name='mary', fullname='Mary Contrary', nickname='mary'), # User(name='fred', fullname='Fred Flintstone', nickname='freddy')]) jack = User(name='amit', fullname='Jack Bean', nickname='gjffdd') jack.addresses = [ Address(email_address='*****@*****.**'), Address(email_address='*****@*****.**') ] #add user table and address table with user id gaurav = User(name='gaurav', fullname='gaurav goyal', nickname='gg') gaurav.addresses = [Address(email_address='*****@*****.**')] #session.add(jack) session.commit() session.close()
from user_controller import UserController from user_view import UserView from user_model import User user_model = User() user_controller = UserController(user_model) user_view = UserView(user_controler) def main(): imprimir_amistad() opcion = inicio_amistad() if opcion == '1': userview.login() elif opcion == '2': userview.registrarse() # ------ main()
def add_user(name, email, message): new_user = User(name=name, email=email, message=message) session.add(new_user) session.commit()
from user_model import User if __name__ == '__main__': u = User()
def add_user(name, surname, phone, date, email, nationality): new_user = User(name = name, surname = surname, phone = phone, date = date, email = email, nationality = nationality) session.add(new_user) session.commit()
def create(self, data): user = User(name=data["name"]) self.session.add(user) self.session.commit() return user.id
def test_user(self): user = User(email='*****@*****.**', password='******', full_name='Teste OSchema', cpf_cnpj="00609568019") # schema = user_schema.UserSchema() # result = schema.dump(user) print(user)
def create_user(name, username, password, team_list): user = User(name=name, username=username, password=password) for team in team_list: user.teams.append(ObjectId(team)) user.save()
insertion = 'insertion' update = 'update' target_function = update user_sql = UserSqlInterface() if target_function == select_all_single_target: results = user_sql.select_all_single_target(type='*', table='users', target_column='id', target_value='7', match_partial=False) elif target_function == insertion: user = User() columns = user.properties_list() columns = tuple(columns[1:len(columns)]) date = datetime.datetime.now() date_str = '%d-%d-%d %d:%d:%d' % (date.year, date.month, date.day, date.hour, date.minute, date.second) pw_handler = PasswordHandler('mypassword') hashed_pw = pw_handler.hash() values = ( hashed_pw, date_str, 0, '*****@*****.**', 'this', 'guy', '*****@*****.**',
def load_user(user_id): user = User() return user