def register(): form = RegForm(request.form) if request.method == 'POST' and form.validate(): create_user(**form.data) flash('Thanks for registering!', 'info') return redirect('/') return render_template('register.html', form=form, title='Register')
def validate_startup(override_first_time_check=False): users = database.get_all_users() if users and not override_first_time_check: return if not users: print("No users found on the system. This is likely the first time the application has been started.") print("Enter new user details below.") username = input("Input username: "******"Input password: ") util.create_user(username, password)
def step01_createUser(self): session = Session() user1 = create_user('GLOBAL', self.email) user2 = create_user('GLOBAL_SCENARIO', self.email) user3 = create_user('NO_NEW_EVENT:NO_INSP:ALL', self.email) user4 = create_user('MMS', None, self.email) session.add(user1) session.add(user2) session.add(user3) session.add(user4) session.commit() Session.remove()
def setUp(self): # Call parent setUp super(UserLoginTests, self).setUp() # Create user data self.user_data = util.create_user(self.driver)
def fill_user_info(): google_id = request.json["google_id"] res = {"new_user": create_user(google_id)} email = request.json.get("email") facebook_id = request.json.get("facebook_id") name = request.json.get("name") age = request.json.get("age") country_name = request.json.get("country_name") is_update = request.json.get("is_update") access_token = request.json.get("access_token") print("Access token:", access_token) user = dbops.get_user_from_google_id(google_id) if access_token: user.google_mobile_access_token = access_token if email: user.email = email if facebook_id: user.facebook_id = facebook_id if name and (not user.name or is_update): user.name = name if age: user.age = int(age) if country_name: country = dbops.get_country_by_name(country_name) if country is not None: user.country_id = country.id dbops.session.commit() return get_response(res, 200)
def setUp(self): # Call parent setUpClass super(UserSmokeTest, self).setUp() # Create user account and login self.user_data = util.create_user(self.driver) util.login(self.driver, self.user_data['username'], self.user_data['password'])
def main(): logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") logging.info("Starting Create User Job") # get config username_to_create = util.must_get_env("USERNAME") password_to_create = util.must_get_env("PASSWORD") # create user and grant super privileges logging.info("Creating User {}".format(username_to_create)) conn = util.connect_memsql() util.create_user(conn, username_to_create, password_to_create) util.grant_user_service_user(conn, username_to_create) util.grant_user_super(conn, username_to_create) logging.info("Done!")
def test_registered_email(self): # Create user data self.user_data = util.create_user(self.driver) #forgetpassowrd with registered email util.forget_password(self.driver, self.user_data['username']) # check for alert alerts = util.get_alert_boxes(self.driver, 'Reset email sent') self.assertEqual(len(alerts), 1)
def create_user(): """ Create a new OSF user """ u = util.create_user() return User( full_name=u['fullname'], email=u['username'], password=u['password'], )
def setUpClass(cls): cls.driver = util.launch_driver() # Create user account and login cls.user_data = util.create_user(cls.driver) util.login( cls.driver, cls.user_data['username'], cls.user_data['password'] )
def setUpClass(cls): # Launch Selenium cls.driver = util.launch_driver() # Create test account cls.user_data = util.create_user(cls.driver) # Login to test account util.login(cls.driver, cls.user_data['username'], cls.user_data['password'])
def setUp(self): # Call parent setUpClass super(UserSmokeTest, self).setUp() # Create user account and login self.user_data = util.create_user(self.driver) util.login( self.driver, self.user_data['username'], self.user_data['password'] )
def test_add_contributor_log(self): """ test to make sure that add contributor log works correctly """ # As of 9 Sep 2013, log says "component"; expected "project" # Log out user_url = self.get_user_url() util.logout(self.driver) # Create second user and get his url second_user_data = util.create_user(self.driver) util.login( self.driver, second_user_data['username'], second_user_data['password'] ) project_url = util.create_project(self.driver) #add contributor self.add_contributor(self.user_data) #get log message_log = self.get_log() #assert the time self._assert_time(message_log.log_time) #assert the log self.assertEqual( message_log.log_text, u'{} added {} as contributor on node {}'.format( second_user_data['fullname'], self.user_data['fullname'], config.project_title, ) ) #check the user_url and project_url self.assertEqual( message_log.log_url[0], self.get_user_url() ) self.assertEqual( message_log.log_url[1], user_url ) self.assertEqual( message_log.log_url[2], project_url.strip('/') )
def adduser(): error = None if request.method == 'POST': username = request.form['username'] password = request.form['pass'] privileges = request.form['privileges'] error = create_user(username, password) error = set_privileges(username, privileges) if error == None: return redirect("/settings") return render_template("add_user.html", privs=get_priv_choices(session.get('user_id')), error=error)
def setUpClass(cls): # Start WebDriver cls.driver = util.launch_driver() # Create test user cls.user_data = util.create_user(cls.driver) # Login to test account util.login( cls.driver, cls.user_data['username'], cls.user_data['password'] )
def test_delete_contributor_log(self): # As of 9 Sep 2013, the log says "component"; expected "project" # Log out user_url = self.get_user_url() util.logout(self.driver) # Create second user and get his url second_user_data = util.create_user(self.driver) util.login( self.driver, second_user_data['username'], second_user_data['password'] ) project_url = util.create_project(self.driver) #add contributor self.add_contributor(self.user_data) time.sleep(3) #remove contributor self.remove_contributor(self.user_data) time.sleep(3) #get log message_log = self.get_log() #assert the time self._assert_time(message_log.log_time) #assert the log self.assertEqual( message_log.log_text, u'{} removed {} as a contributor from project {}'.format( second_user_data["fullname"], self.user_data['fullname'], config.project_title ) ) #check the second user_url, first user_url and project_url self.assertEqual(message_log.log_url[0], self.get_user_url()) self.assertEqual(message_log.log_url[1], user_url) self.assertEqual(message_log.log_url[2]+"/", project_url)
def setUp(self): # Start WebDriver self.driver = util.launch_driver() # Create test user self.user_data = util.create_user(self.driver) # Login to test account util.login( self.driver, self.user_data['username'], self.user_data['password'] ) # Create project and store URL self.url = util.create_project(self.driver)
def createuser(): error = None if request.method == 'POST': username = request.form['username'] password = request.form['password'] password_conf = request.form['password-conf'] if password != password_conf: error = "Passwords do not match" else: error = create_user(username, password) logged_in, user = validate_creds(username, password) if not logged_in: error = 'Invalid Credentials. Please try again.' if error == None: session['user_id'] = user return redirect("/settings") return render_template("createuser.html", error=error)
def setUpClass(cls): # Start WebDriver cls.driver = webdriver.Firefox() # cls.driver.implicitly_wait(5) # Create user account and login cls.user_data = util.create_user(cls.driver) util.login(cls.driver, cls.user_data['username'], cls.user_data['password']) # Create test project and store URL cls.project_url = util.create_project(cls.driver) # Log out util.logout(cls.driver)
def setUpClass(cls): # Start WebDriver cls.driver = webdriver.Firefox() # cls.driver.implicitly_wait(5) # Create user account and login cls.user_data = util.create_user(cls.driver) util.login( cls.driver, cls.user_data['username'], cls.user_data['password'] ) # Create test project and store URL cls.project_url = util.create_project(cls.driver) # Log out util.logout(cls.driver)
def test_node_add_contributor_log(self): """ test to make sure that project log works correctly on adding contributor to a node """ # Log out user_url=self.get_user_url() util.logout(self.driver) # Create second user and get his url second_user_data = util.create_user(self.driver) util.login( self.driver, second_user_data['username'], second_user_data['password'] ) util.create_project(self.driver) util.create_node(self.driver) self.driver.find_element_by_css_selector("li span a").click() new_node_url=self.driver.current_url #add contributor self.add_contributor(self.user_data) #get log util.goto_project(self.driver) message_log = self.get_log() #assert the time self._assert_time(message_log.log_time) #assert the log self.assertEqual(message_log.log_text, second_user_data["fullname"] + " added " + self.user_data['fullname'] + " as contributor on node " + config.node_title) #check the second user_url, first user_url and node_url self.assertEqual(message_log.log_url[0], self.get_user_url()) self.assertEqual(message_log.log_url[1], user_url) self.assertEqual(message_log.log_url[2]+"/", new_node_url)
def test_node_add_contributor_log(self): """ test to make sure that project log works correctly on adding contributor to a node """ # Log out user_url = self.get_user_url() util.logout(self.driver) # Create second user and get his url second_user_data = util.create_user(self.driver) util.login(self.driver, second_user_data['username'], second_user_data['password']) util.create_project(self.driver) util.create_node(self.driver) self.driver.find_element_by_css_selector("li span a").click() new_node_url = self.driver.current_url #add contributor self.add_contributor(self.user_data) #get log util.goto_project(self.driver) message_log = self.get_log() #assert the time self._assert_time(message_log.log_time) #assert the log self.assertEqual( message_log.log_text, second_user_data["fullname"] + " added " + self.user_data['fullname'] + " as contributor on node " + config.node_title) #check the second user_url, first user_url and node_url self.assertEqual(message_log.log_url[0], self.get_user_url()) self.assertEqual(message_log.log_url[1], user_url) self.assertEqual(message_log.log_url[2] + "/", new_node_url)
def create_user(self, name): return util.create_user(name)
def test_create_user(): util.create_user()
def create_user(self): return util.create_user(self.driver)
def create_user(): """ Create a new OSF user """ u = util.create_user() return User(full_name=u["fullname"], email=u["username"], password=u["password"])
def create_user(self, name): return util.create_user(self.client, name)
def gconnect(): # Validate state token if request.args.get('state') != login_session['state']: response = make_response(json.dumps('Invalid state parameter.'), 401) response.headers['Content-Type'] = 'application/json' return response # Obtain authorization code code = request.data try: # Upgrade the authorization code into a credentials object oauth_flow = flow_from_clientsecrets('client_secrets.json', scope='') oauth_flow.redirect_uri = 'postmessage' credentials = oauth_flow.step2_exchange(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]) r = requests.get(url=url) result = r.json() # 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' return response # Verify that the access token is used for the intended user. gplus_id = credentials.id_token['sub'] if result['user_id'] != gplus_id: response = make_response( json.dumps("Token's user ID doesn't match given user ID."), 401) response.headers['Content-Type'] = 'application/json' return response # Verify that the access token is valid for this app. if result['issued_to'] != CLIENT_ID: response = make_response( json.dumps("Token's client ID does not match app's."), 401) print("Token's client ID does not match app's.") response.headers['Content-Type'] = 'application/json' return response stored_access_token = login_session.get('access_token') stored_gplus_id = login_session.get('gplus_id') if stored_access_token is not None and gplus_id == stored_gplus_id: response = make_response( json.dumps('Current user is already connected.'), 200) response.headers['Content-Type'] = 'application/json' login_session['access_token'] = credentials.access_token return response # Store the access token in the session for later use. login_session['access_token'] = credentials.access_token login_session['gplus_id'] = gplus_id # Get user info 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() login_session['username'] = data['name'] login_session['picture'] = data['picture'] login_session['email'] = data['email'] create_user(login_session, session) # print(u"Existing User %s Logged in" % user.name ) output = '' output += '<h1>Welcome, ' output += login_session['username'] output += '!</h1>' output += '<img src="' output += login_session['picture'] output += (' " style = "width: 300px; height: 300px;' + 'border-radius: 150px;-webkit-border-radius: 150px;' + '-moz-border-radius: 150px;"> ') flash("you are now logged in as %s" % login_session['username']) print("Logged in!") return output