通过JS使用Twitter登录自己的网站

哎,google了一天,终于把这个功能给弄出来了、忍不住要写一篇博客来记录一下我的成果!!!!
咳咳咳,首先你的电脑必须能翻墙,这个是前提哈

1. 注册Twitter账号

2. 进入https://apps.twitter.com/app 新建一个项目

3. 进入https://auth-server.herokuapp.com/,登录,然后新建一个项目,把你在Twitter中新建的项目的Consumer Key和Consumer Secret设置到这个新建的项目中,在这个项目里reference可随便填写、最好与项目相关,domain为你的项目域名,测试可用localhost(测试了可行),

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
前端代码如下,使用了Bootstrap框架和jQuery库: ```html <!DOCTYPE html> <html> <head> <title>登陆页面</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>登陆</h2> <form action="/login" method="post"> <div class="form-group"> <label for="username">用户名:</label> <input type="text" class="form-control" id="username" placeholder="请输入用户名" name="username"> </div> <div class="form-group"> <label for="password">密码:</label> <input type="password" class="form-control" id="password" placeholder="请输入密码" name="password"> </div> <button type="submit" class="btn btn-primary">登陆</button> </form> </div> </body> </html> ``` 后端使用python的Flask框架实现,具体代码如下: ```python from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def index(): return render_template('login.html') @app.route('/login', methods=['POST']) def login(): username = request.form['username'] password = request.form['password'] if username == 'admin' and password == '123456': return '登陆成功' else: return '用户名或密码错误' if __name__ == '__main__': app.run() ``` 其中,`@app.route('/login', methods=['POST'])`指定了接收POST请求的路由和处理函数,`request.form`可以获取前端发送的表单数据。这里只是简单的判断了用户名和密码是否正确,实际应用中应该使用加密算法对密码进行加密存储,以提高安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值