def register(self): Session = sessionmaker(bind=engine) session = Session() try: if self.lineEdit.text() == '' or self.lineEdit_2.text() == '': CommonUtil.hint_dialog(self, CommonUtil.APP_ICON, '提示', '请输入用户名和密码') return users = session.query(user).filter( user.name == self.lineEdit.text()) if users.count() >= 1: CommonUtil.hint_dialog(self, CommonUtil.APP_ICON, '提示', '用户已经存在~') return else: newuser = user() newuser.name = self.lineEdit.text().strip() newuser.password = self.lineEdit_2.text().strip() session.add(newuser) session.commit() except Exception as e: print(e.args) finally: session.close()
def insert(self, username, password): try: users = user(username=username, password=password) users.save() return "注册成功" except Exception, e: return "注册出错"
def test_favorite_updata(self): # お気に入り登録したいアーティストのデータ u1 = user() u1.attr["id"] = 1 u1.attr["email"] = "*****@*****.**" u1.attr["genre"] = "rock" u1.attr["sex"] = "female" u1.attr["fan_class"] = "twenties" u1.attr["artist_name"] = "爆弾ジョニー" u1.attr["password"] = "******" artist_1 = u1.save() # お気に入り登録をするサポーターのデータ u = user() u.attr["id"] = 2 u.attr["email"] = "*****@*****.**" u.attr["password"] = "******" suporter_1 = u.save() u.attr["favorite"] = 1 result = u.favorite_update() self.assertEqual(suporter_1, result) self.assertTrue(type(result) is int) self.assertTrue(u.attr["id"] is not None) self.assertTrue(u.attr["genre"] is None) self.assertTrue(u.attr["sex"] is None) self.assertTrue(u.attr["fan_class"] is None) self.assertTrue(u.attr["artist_name"] is None) self.assertTrue(u.attr["favorite"] is not None) self.assertTrue(u.attr["password"] is not None) u.attr["favorite"] = 2 result = u.favorite_update() self.assertEqual(suporter_1, result) self.assertTrue(type(result) is int) self.assertTrue(u.attr["id"] is not None) self.assertTrue(u.attr["genre"] is None) self.assertTrue(u.attr["sex"] is None) self.assertTrue(u.attr["fan_class"] is None) self.assertTrue(u.attr["artist_name"] is None) self.assertTrue(u.attr["favorite"] is not None) self.assertTrue(u.attr["password"] is not None)
def setUp(self): self.u = user() self.u.attr["email"] = "*****@*****.**" self.u.attr["favorite"] = 1 self.u.attr["password"] = "******" self.patcher = mock.patch('model.project.project.name', return_value="test_db_artist") self.mock_name = self.patcher.start() user.migrate() self.u.save()
def post(self): # パラメータの取得 _email = self.get_argument("email", None) _genre = self.get_argument("sound", None) _sex = self.get_argument("sex", None) _age = self.get_argument("age", None) _artist_name = self.get_argument("artist_name", None) _raw_pass = self.get_argument("password", None) # 入力項目の必須チェック errors = [] if _email == None: errors.append("ID(Email Address) is required.") if _genre == None: errors.append("Genre is required.") if _sex == None: errors.append("Sex is required.") if _age == None: errors.append("Age is required.") if _artist_name == None: errors.append("Artist's name is required.") if _raw_pass == None: errors.append("Password is required.") if len(errors) > 0: # エラーはサインイン画面に渡す self.render("signupArtist.html", errors=errors, messages=[]) return # 入力されたパスワードをsha224で一方向の暗号化 _pass = hashlib.sha224(_raw_pass.encode()).hexdigest() # メールアドレスでユーザー情報を取得 u = user.find_by_email(_email) # メールアドレスの重複を許可しない if u is not None: self.render("signupArtist.html", errors=["The ID(Email Address) cannot be used."], messages=[]) return # ユーザー情報を保存 u = user() u.attr["email"] = _email u.attr["genre"] = _genre u.attr["sex"] = _sex u.attr["fan_class"] = _age u.attr["artist_name"] = _artist_name u.attr["password"] = _pass u.save_artist() # サインイン画面へリダイレクト(サインイン完了の旨を添えて) self.redirect("/loginArtist?message=%s" % tornado.escape.url_escape( "Sign up is complete. Please continue to sign in."))
def read_accounts(self, data_base, accounts): self.open_connection(data_base) cursor = self.conn.cursor() cursor.execute(self.QUERY_USER_SELECT) result_set = cursor.fetchall() for result in result_set: new_user = user(result[1], result[2]) record = account(result[0], result[3], new_user) accounts.append(record) self.close_connection()
def read_accounts(self, file_name, accounts): self.open_file(file_name) for line in self.input_file: user_account = line.split() new_user = user(user_account[2], user_account[3]) record = account(int(user_account[0]), int(user_account[1]), new_user) #print(record.get_identifier(), record.get_password(), record.get_user().get_name(), record.get_user().get_email()) accounts.append(record) """for line in self.input_file:
def setUp(self): self.u = user() self.u.attr["email"] = "*****@*****.**" self.u.attr["genre"] = "rock" self.u.attr["sex"] = "female" self.u.attr["fan_class"] = "twenties" self.u.attr["artist_name"] = "爆弾ジョニー" self.u.attr["favorite"] = None self.u.attr["password"] = "******" self.patcher = mock.patch('model.project.project.name', return_value="test_db_artist") self.mock_name = self.patcher.start() user.migrate() self.u.save()
def test_save_UPDATE(self): u = user() u.attr["email"] = "*****@*****.**" u.attr["password"] = "******" result = u.save() self.assertTrue(type(result) is int) self.assertTrue(u.attr["id"] is not None) self.assertTrue(u.attr["genre"] is None) self.assertTrue(u.attr["sex"] is None) self.assertTrue(u.attr["fan_class"] is None) self.assertTrue(u.attr["artist_name"] is None) self.assertTrue(u.attr["favorite"] is None) self.assertTrue(u.attr["password"] is not None)
def test_save_INSERT(self): u = user() u.attr["email"] = "*****@*****.**" u.attr["password"] = "******" result = u.save() self.assertTrue(type(result) is int) self.assertTrue(u.attr["id"] is not None) self.assertTrue(u.attr["genre"] is None) self.assertTrue(u.attr["sex"] is None) self.assertTrue(u.attr["fan_class"] is None) self.assertTrue(u.attr["artist_name"] is None) self.assertTrue(u.attr["favorite"] is None) self.assertTrue(u.attr["password"] is not None)
def create_account(self): self.screen.display_message("\nPlease enter your name:") name = self.keypad.get_input() self.screen.display_message("\nEnter your email:") email = self.keypad.get_input() self.screen.display_message("\nEnter your password:"******"\nAccount registered successfully!") self.screen.display_message( "\nUse your account identifier \'{}\' to sign in!".format( new_user_identifier))
def test_save_UPDATE(self): u = user() u.attr["id"] = 1 u.attr["email"] = "*****@*****.**" u.attr["genre"] = "alternative" u.attr["sex"] = "female" u.attr["fan_class"] = "twenties" u.attr["artist_name"] = "SAMURAIMANZGROOVE" u.attr["password"] = "******" result = u.save() self.assertTrue(type(result) is int) self.assertTrue(u.attr["id"] is not None) self.assertTrue(u.attr["genre"] is not None) self.assertTrue(u.attr["sex"] is not None) self.assertTrue(u.attr["fan_class"] is not None) self.assertTrue(u.attr["artist_name"] is not None) self.assertTrue(u.attr["favorite"] is None) self.assertTrue(u.attr["password"] is not None)
def post(self): # パラメータの取得 _email = self.get_argument("email", None) _raw_pass = self.get_argument("password", None) # 入力項目の必須チェック _errors = [] if _email == None: _errors.append("ID(Email Address) is required.") if _raw_pass == None: _errors.append("Password is required.") if len(_errors) > 0: # エラーはサインイン画面に渡す self.render("signupUser.html", errors=_errors, messages=[]) return # 入力されたパスワードをsha224で一方向の暗号化 _pass = hashlib.sha224(_raw_pass.encode()).hexdigest() # メールアドレスでユーザー情報を取得 u = user.find_by_email(_email) # メールアドレスの重複を許可しない if u is not None: self.render("signupUser.html", errors=["The ID(Email Address) cannot be used."], messages=[]) return # ユーザー情報を保存 u = user() u.attr["email"] = _email u.attr["password"] = _pass u.save() # サインイン画面へリダイレクト(サインイン完了の旨を添えて) self.redirect("/login?message=%s" % tornado.escape.url_escape( "Sign up is complete. Please continue to sign in."))
def test_artist_all(self): user.migrate() # 全一致のデータ u1 = user() u1.attr["email"] = "*****@*****.**" u1.attr["genre"] = "rock" u1.attr["sex"] = "female" u1.attr["fan_class"] = "twenties" u1.attr["artist_name"] = "爆弾ジョニー" u1.attr["password"] = "******" artist_1 = u1.save() # genre, sex 一致のデータ u2 = user() u2.attr["email"] = "*****@*****.**" u2.attr["genre"] = "rock" u2.attr["sex"] = "female" u2.attr["fan_class"] = "thirties" u2.attr["artist_name"] = "ONIGAWARA" u2.attr["password"] = "******" artist_2 = u2.save() # sex, fan_class 一致のデータ u3 = user() u3.attr["email"] = "*****@*****.**" u3.attr["genre"] = "alternative" u3.attr["sex"] = "female" u3.attr["fan_class"] = "twenties" u3.attr["artist_name"] = "SAMURAIMANZGROOVE" u3.attr["password"] = "******" artist_3 = u3.save() # genre, fan_class 一致のデータ u4 = user() u4.attr["email"] = "*****@*****.**" u4.attr["genre"] = "rock" u4.attr["sex"] = "male" u4.attr["fan_class"] = "twenties" u4.attr["artist_name"] = "ビレッジマンズストア" u4.attr["password"] = "******" artist_4 = u4.save() # genre 一致のデータ u5 = user() u5.attr["email"] = "*****@*****.**" u5.attr["genre"] = "rock" u5.attr["sex"] = "male" u5.attr["fan_class"] = "thirties" u5.attr["artist_name"] = "みそっかす" u5.attr["password"] = "******" artist_5 = u5.save() # sex 一致のデータ u6 = user() u6.attr["email"] = "*****@*****.**" u6.attr["genre"] = "alternative" u6.attr["sex"] = "female" u6.attr["fan_class"] = "forties" u6.attr["artist_name"] = "SOPHIA" u6.attr["password"] = "******" artist_6 = u6.save() # fan_class 一致のデータ u7 = user() u7.attr["email"] = "*****@*****.**" u7.attr["genre"] = "alternative" u7.attr["sex"] = "male" u7.attr["fan_class"] = "twenties" u7.attr["artist_name"] = "バックドロップシンデレラ" u7.attr["password"] = "******" artist_7 = u7.save() # 一個も一致しないデータ u8 = user() u8.attr["email"] = "*****@*****.**" u8.attr["genre"] = "alternative" u8.attr["sex"] = "male" u8.attr["fan_class"] = "thirties" u8.attr["artist_name"] = "八十八ヶ所巡礼" u8.attr["password"] = "******" artist_8 = u8.save() # ユーザーのデータ u9 = user() u9.attr["email"] = "*****@*****.**" u9.attr["password"] = "******" suporter_1 = u9.save() u10 = user() u10.attr["email"] = "*****@*****.**" u10.attr["password"] = "******" suporter_2 = u10.save() artist_all = user.artist_all() self.assertEqual(len(artist_all), 8)
def test_search_artists(self): genre = "rock" sex = "female" fan_class = "twenties" user.migrate() # 全一致のデータ u1 = user() u1.attr["email"] = "*****@*****.**" u1.attr["genre"] = "rock" u1.attr["sex"] = "female" u1.attr["fan_class"] = "twenties" u1.attr["artist_name"] = "爆弾ジョニー" u1.attr["password"] = "******" artist_1 = u1.save() # genre, sex 一致のデータ u2 = user() u2.attr["email"] = "*****@*****.**" u2.attr["genre"] = "rock" u2.attr["sex"] = "female" u2.attr["fan_class"] = "thirties" u2.attr["artist_name"] = "ONIGAWARA" u2.attr["password"] = "******" artist_2 = u2.save() # sex, fan_class 一致のデータ u3 = user() u3.attr["email"] = "*****@*****.**" u3.attr["genre"] = "alternative" u3.attr["sex"] = "female" u3.attr["fan_class"] = "twenties" u3.attr["artist_name"] = "SAMURAIMANZGROOVE" u3.attr["password"] = "******" artist_3 = u3.save() # genre, fan_class 一致のデータ u4 = user() u4.attr["email"] = "*****@*****.**" u4.attr["genre"] = "rock" u4.attr["sex"] = "male" u4.attr["fan_class"] = "twenties" u4.attr["artist_name"] = "ビレッジマンズストア" u4.attr["password"] = "******" artist_4 = u4.save() # genre 一致のデータ u5 = user() u5.attr["email"] = "*****@*****.**" u5.attr["genre"] = "rock" u5.attr["sex"] = "male" u5.attr["fan_class"] = "thirties" u5.attr["artist_name"] = "みそっかす" u5.attr["password"] = "******" artist_5 = u5.save() # sex 一致のデータ u6 = user() u6.attr["email"] = "*****@*****.**" u6.attr["genre"] = "alternative" u6.attr["sex"] = "female" u6.attr["fan_class"] = "forties" u6.attr["artist_name"] = "SOPHIA" u6.attr["password"] = "******" artist_6 = u6.save() # fan_class 一致のデータ u7 = user() u7.attr["email"] = "*****@*****.**" u7.attr["genre"] = "alternative" u7.attr["sex"] = "male" u7.attr["fan_class"] = "twenties" u7.attr["artist_name"] = "バックドロップシンデレラ" u7.attr["password"] = "******" artist_7 = u7.save() # 一個も一致しないデータ u8 = user() u8.attr["email"] = "*****@*****.**" u8.attr["genre"] = "alternative" u8.attr["sex"] = "male" u8.attr["fan_class"] = "thirties" u8.attr["artist_name"] = "八十八ヶ所巡礼" u8.attr["password"] = "******" artist_8 = u8.save() self.assertEqual(u1.attr["id"], 1) self.assertEqual(u2.attr["id"], 2) self.assertEqual(u3.attr["id"], 3) self.assertEqual(u4.attr["id"], 4) self.assertEqual(u5.attr["id"], 5) self.assertEqual(u6.attr["id"], 6) self.assertEqual(u7.attr["id"], 7) self.assertEqual(u8.attr["id"], 8) artist_list = user.search_artists(genre, sex, fan_class) self.assertEqual(len(artist_list), 1) self.assertTrue(type(artist_list[0]) is user) artist_list_gs = user.search_artists(genre, sex, '') self.assertEqual(len(artist_list_gs), 2) self.assertTrue(type(artist_list_gs[0]) is user) self.assertTrue(type(artist_list_gs[1]) is user) artist_list_sf = user.search_artists('', sex, fan_class) self.assertEqual(len(artist_list_sf), 2) self.assertTrue(type(artist_list_sf[0]) is user) self.assertTrue(type(artist_list_sf[1]) is user) artist_list_gf = user.search_artists(genre, '', fan_class) self.assertEqual(len(artist_list_gf), 2) self.assertTrue(type(artist_list_gf[0]) is user) self.assertTrue(type(artist_list_gf[1]) is user) artist_list_g = user.search_artists(genre, '', '') self.assertEqual(len(artist_list_g), 4) self.assertTrue(type(artist_list_g[0]) is user) self.assertTrue(type(artist_list_g[1]) is user) self.assertTrue(type(artist_list_g[2]) is user) self.assertTrue(type(artist_list_g[3]) is user) artist_list_s = user.search_artists('', sex, '') self.assertEqual(len(artist_list_s), 4) self.assertTrue(type(artist_list_s[0]) is user) self.assertTrue(type(artist_list_s[1]) is user) self.assertTrue(type(artist_list_s[2]) is user) self.assertTrue(type(artist_list_s[3]) is user) artist_list_f = user.search_artists('', '', fan_class) self.assertEqual(len(artist_list_f), 4) self.assertTrue(type(artist_list_f[0]) is user) self.assertTrue(type(artist_list_f[1]) is user) self.assertTrue(type(artist_list_f[2]) is user) self.assertTrue(type(artist_list_f[3]) is user) artist_list_all = user.search_artists('', '', '') self.assertEqual(len(artist_list_all), 8) self.assertTrue(type(artist_list_all[0]) is user) self.assertTrue(type(artist_list_all[1]) is user) self.assertTrue(type(artist_list_all[2]) is user) self.assertTrue(type(artist_list_all[3]) is user) self.assertTrue(type(artist_list_all[4]) is user) self.assertTrue(type(artist_list_all[5]) is user) self.assertTrue(type(artist_list_all[6]) is user) self.assertTrue(type(artist_list_all[7]) is user)