npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

passport-leancloud

v0.0.3

Published

Passport Strategy for LeanCloud.cn

Downloads

16

Readme

passport-leancloud

云引擎中使用 AVUser 作为 passport 策略。

如何使用

安装

源代码安装

clone 到本地项目,并且放进 node_modules 文件夹中:

	git clone https://github.com/wujun4code/passport-leancloud

通过 npm 安装

	npm install passport-leancloud

编写代码

Express 项目中的 app.js 编写如下代码:

    var express = require('express');
	var passport = require('passport');
	var LeanCloudStrategy = require('passport-leancloud');

创建 configuration

	var leancloudStrategy = new LeanCloudStrategy({
		appId:'{这里填写 LeanCloud AppId}'
		appKey:'{这里填写 LeanCloud AppKey}'
	});

启用策略:

	passport.use(leancloudStrategy);

配合 Express 使用:

   var app = express();
   app.use(passport.initialize());
   app.use(passport.session());

在需要验证的路由当中使用方式如下:

app.get('/login', function(req, res) {
  res.render('login');
});
app.post('/login',
  passport.authenticate('leancloud', {
    successRedirect: '/',
    failureRedirect: '/login',
  })
);

// passport 必要的序列化和反序列化
passport.serializeUser(function(user, done) {
  console.log('serializeUser');
  console.log(user);
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  console.log('deserializeUser');
  done(null, user);
});

login 对应的 view 代码可以如下:

<!DOCTYPE HTML>
<html>
  <head>
    <title>passport-leancloud</title>
  </head>
  <body>
        <form action="/login" method="post">
          <label>用户名:</label>
          <input id="username" type="text" name="username" autocomplete="on" placeholder="用户名">
          <label >密码:</label>
          <input id="password" type="password" name="password" autocomplete="on" placeholder="密码">
          <input type="submit" value="登陆"/>
        </form>
  </body>
</html>