예제 #1
0
def subscribeHandler(dom):
    """处理订阅事件"""
    fromname = dom.find('FromUserName').text
    add_user(fromname)
    context=get_context(dom)
    context['content']=u"欢迎您订阅乐翻淘,我们将为您提供各种高性价比的购物推荐。现在您可以回复对应的编号查询最新的网购促销信息"
    return render_template('erro.html',**context)
예제 #2
0
def subscribeHandler(dom):
    """处理订阅事件"""
    fromname = dom.find('FromUserName').text
    add_user(fromname)
    context = get_context(dom)
    context['content'] = u"欢迎您订阅乐翻淘,我们将为您提供各种高性价比的购物推荐。现在您可以回复对应的编号查询最新的网购促销信息"
    return render_template('erro.html', **context)
예제 #3
0
def login_success(token, profile):
    whitelisted_domains = config.get("google_login", "whitelisted_domains")
    if not is_valid_email_domain(profile.get("hd"), whitelisted_domains):
        return jsonify(error="Please use a valid email address!")
    add_user(session, token, profile)
    session["seen"] = True
    return redirect(url_for("my_predictions"))
예제 #4
0
def login_success(token, profile):
    whitelisted_domains = config.get("google_login", "whitelisted_domains")
    if not is_valid_email_domain(profile.get("hd"), whitelisted_domains):
        return jsonify(error="Please use a valid email address!")
    add_user(session, token, profile)
    session["seen"] = True
    return redirect(url_for("my_predictions"))
예제 #5
0
    def process_item(self, item, spider):
        # content = "%s\t%s\n" % (item['uid'], item['name'])
        # self.file.write(content)
        # self.file.flush()

        data = dict(item)
        add_user(data)
        remove_user_url(data['url'])

        return item
예제 #6
0
def add_new_user():
    form = NewUserForm()
    if form.validate_on_submit():
        name = form.name.data,
        email = form.email.data,
        phone = form.phone.data,
        mobile_phone = form.mobile_phone.data,
        status = form.status.data
        add_user(name, email, phone, mobile_phone, status)
        flash('User created successfully', 'success')
        return redirect(url_for('users.all_users'))
    return render_template('add_user.html', form=form, title=title)
예제 #7
0
def login():
    if request.method=="GET":
        return render_template('login.html')
    elif request.method=="POST":
        if request.form['button']=='GOOGLE':
            url=googleauth.build_redirect_url()
            return redirect(url)
        elif request.form['button']=='Login':
            username=request.form['username']
            utils.add_user(username)
            session["user"]=username
            return redirect(url_for("about"))
예제 #8
0
 def main(message):
     try:
         utils.add_user(message=message, db_name=self.cfg['db_name'])
         if message.text in self.commands:
             self.commands[message.text](message)
         else:
             self.bot.send_message(message.chat.id,
                                   text=self.cfg['base_message'],
                                   reply_markup=utils.repl_markup(
                                       list(self.commands.keys())))
     except Exception as e:
         utils.log(e)
예제 #9
0
 def test_main_with_users(self):
     """
     Ensure main route behaves correctly when users have been
     added to the db
     """
     add_user('mans', '*****@*****.**', 'password1234')
     add_user('wayua', '*****@*****.**', 'password1234')
     response = self.client.get('/')
     self.assertEqual(response.status_code, 200)
     self.assertIn(b'<h1>All users</h1>', response.data)
     self.assertNotIn(b'<p>No users!</p>', response.data)
     self.assertIn(b'<strong>mans</strong>', response.data)
     self.assertIn(b'<strong>wayua</strong>', response.data)
예제 #10
0
def googleoauth2callback():
    # this code comes from the google login page
    code=request.args.get('code','')

    # if we didn't get a code, go back to login
    if code=='':
        return redirect(url_for('login'))

    # We have a code so we have to convert it to an access token
    access_token = googleauth.code_to_access_token(code)

    # and convert it to userinfo
    userinfo=googleauth.access_token_to_info(access_token)
    session['user']=userinfo['email']
    utils.add_user(userinfo['email'])
    return redirect(url_for('about'));
예제 #11
0
def add_user(request):
    if request.method == 'POST':
        user = request.user.userBaseInfo
        if not user.user.is_superuser:
            return JsonResponse({'status': 501, 'msg': '权限不足'})
        else:
            username = request.POST.get('username', '')
            name = request.POST.get('name', '')
            group = request.POST.get('group', 'student')
            institute = request.POST.get('institute', '')
            major = request.POST.get('major', '')
            student_class = request.POST.get('student_class', '')
            Config = WebsiteConfig.objects.all()[0]
            user = utils.add_user(username, name, Config.default_password,
                                  group)
            if user is not None:
                try:
                    ins = Institute.objects.get(name=institute)
                    m = ins.major.get(name=major)
                    c = m.student_class.get(name=student_class)
                    user.student_class = c
                    user.save()
                except:
                    pass
                return JsonResponse({
                    'status': 201,
                    'msg': '添加成功',
                    'content': user.get_dict()
                })
            else:
                return JsonResponse({'status': 503, 'msg': '重复的账号'})
    return JsonResponse({'status': 505, 'msg': '不支持的操作'})
예제 #12
0
파일: views.py 프로젝트: thequbit/bits
def web_add_user(request):

    result = {'success': False}
    #if True:
    try:
    
        user, token = check_auth(request)
        
        organization_id = request.POST['organization_id']
        user_type_id = request.POST['user_type_id']
        first = request.POST['first']
        last = request.POST['last']
        email = request.POST['email']
        password = request.POST['password']

        
        new_user = add_user(
            user = user,
            organization_id = organization_id,
            user_type_id = user_type_id,
            first = first,
            last = last,
            email = email,
            password = password,
        )
        
        result['new_user_id'] = new_user.id
        
        result['success'] = True
        
    except:
        pass
        
    return make_response(result)
예제 #13
0
 def test_all_users(self):
     """
     Ensure all users behaves correctly
     """
     created = datetime.datetime.utcnow() + datetime.timedelta(-30)
     add_user('mans', '*****@*****.**', 'password1234', created)
     add_user('wayua', '*****@*****.**', 'password1234')
     with self.client:
         response = self.client.get('/users')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertEqual(len(data['data']['users']), 2)
         self.assertTrue('created_at' in data['data']['users'][0])
         self.assertTrue('created_at' in data['data']['users'][1])
         self.assertIn('mans', data['data']['users'][1]['username'])
         self.assertIn('*****@*****.**', data['data']['users'][1]['email'])
         self.assertIn('wayua', data['data']['users'][0]['username'])
         self.assertIn('*****@*****.**', data['data']['users'][0]['email'])
         self.assertIn('success', data['status'])
예제 #14
0
def register():
	if request.method == "GET":
		return(render_template("register.html"))
	else:
		uname = request.form['username']
		pword = request.form['password']
		conf = request.form['confirm']
		email = request.form['email']
		if utils.user_exists(uname):
			return(render_template("register.html",message="Username already exists."))
		elif len(uname) < 2:
			return(render_template("register.html",message="Username must be at least 2 characters."))
		elif len(pword) < 6:
			return(render_template("register.html",message="Password must be at least 6 characters."))
		elif pword != conf:
			return(render_template("register.html",message="Password doesn't match confirmation."))
		else:
			utils.add_user(uname,pword,email)
			return redirect(url_for('login'))
예제 #15
0
파일: action.py 프로젝트: tianbao666/xly1
def logic():
    # 读取文件
    # 如果输入无效的操作,则反复操作, 否则输入exit退出
    while True:
        try:
            # 业务逻辑
            info = input("\033[1;35mPlease input your operation: \033[0m")
            # string -> list
            input_list = info.split()
            action = input_list[0]
            userinfo_list = input_list[1:]
            #userinfo_string = ' '.join(userinfo_list[1:])

            if action == "add":
                res = add_user(userinfo_list)
                print(res)
            elif action == "delete" or action == "del":
                # .remove
                res = del_user(userinfo_list)
                print(res)
            elif action == "find":
                res = find_info(userinfo_list)
                print(res)
            elif action == "update":
                res = update_info(userinfo_list)
                print(res)
            elif action == "list":
                get_list()
            elif action == "display":
                res = get_pageinfo(userinfo_list)
                print(res)
            # elif action == "export":
            #     res = csv_export()
            #     print(res)
            elif action == "help" or action == "h":
                print(help_info)
            elif action == "exit":
                sys.exit(0)
            else:
                print("\033[1;36m输入错误,请输入 help 查看帮助!\033[0m\n")
        except IndexError:
            print('\033[1;36m[Errno] list index out of range.\033[0m\n')
        except FileNotFoundError:
            print('\033[1;36m[Errno] No such file or directory.\033[0m\n')
        except TypeError:
            print('\033[1;36m[Errno] Type Error.\033[0m\n')
        except KeyError:
            print('\033[1;36m[Errno] Key Error.\033[0m\n')
        except Exception as e:
            print(e)


# logic()
예제 #16
0
 def test_single_user(self):
     """
     Ensure a single user behaves correctly
     """
     user = add_user('mans', '*****@*****.**', 'password1234')
     with self.client:
         response = self.client.get(f'/users/{user.id}')
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertTrue('created_at' in data['data'])
         self.assertIn('mans', data['data']['username'])
         self.assertIn('*****@*****.**', data['data']['email'])
         self.assertIn('success', data['status'])
예제 #17
0
def auth():
    if "user_id" in session:
        return redirect("/")

    code = request.args.get("code")
    state = request.args.get("state")

    if not code or state != session.get("state"):
        flash("""Oops. We couldn't authorize your Github account; 
                 please try again.""")
        return redirect("/")

    payload = {
        "client_id": os.environ.get("CLIENT_ID"),
        "client_secret": os.environ.get("CLIENT_SECRET"),
        "code": code,
        "state": session["state"]
    }
    # Unless user includes a scope, default to read-only public data.
    if "scope" in session:
        payload["scope"] = config.OAUTH_SCOPE

    r = requests.post(config.GITHUB_AUTH_REQUEST_TOKEN_URL, params=payload)
    access_token = urllib.parse.parse_qs(r.text).get("access_token")
    if not access_token:
        flash("""Oops. We couldn't authorize your Github account; 
                 please try again.""")
        return redirect("/")
    access_token = access_token[0]

    g = api_utils.get_auth_api(access_token)
    user = g.get_user()
    utils.add_user(user)
    db_utils.account_login(user, access_token)
    session["user_id"] = user.id
    session["access_token"] = access_token

    flash("Successfully authenticated {} with Github!".format(user.login))
    return redirect("/")
예제 #18
0
    def run(self):
        br = init_browser()

        # go straight for sign up
        timer=add_user(br)
        self.custom_timers[ timer[0] ]=timer[1]
예제 #19
0
                username = input("Enter username: "******"Full name: ")
        username = input("Username: "******"E-mail: ")

        try:
            utils.add_user(users=users,
                           full_name=full_name,
                           username=username,
                           email=email)
            print("Added user")

        except Exception as exception:
            print(exception)

    elif action == 3:
        print("Enter 1 to delete by e-mail 2 to delete by username")
        delete_by = int(input("Your input: "))

        try:
            if delete_by == 1:
                email = input("Enter e-mail: ")
                user = utils.delete_user_by_email(users=users,
                                                  email=email)
예제 #20
0
def handle_start(bot, update):
    user = update.message.chat.id
    if len(utils.get_user(user)) == 0:  # if new user - add it to the users list and suggest choosing categories
        utils.add_user(user)
        bot.send_message(user, 'start_text')  # добавить стартовый текст в конфиг
        bot.send_message(user, utils.generate_text(user), reply_markup=utils.generate_keyboard(user))