leancloud / node-js-getting-started Goto Github PK
View Code? Open in Web Editor NEWLeanEngine Node.js getting started.
Home Page: https://leancloud.cn/docs/leanengine_overview.html
LeanEngine Node.js getting started.
Home Page: https://leancloud.cn/docs/leanengine_overview.html
Deploy to Leancloud not working.
connect-flash
和flash
这两个包都试过了。
router.get('/login', (req, res) => {
// 判断用户是否已经登录
if (req.currentUser) {
// 如果已经登录,发送当前登录用户信息。
res.redirect('/users/profile')
} else {
// 没有登录,跳转到登录页面。
console.log(req)
res.render('login', {message: req.flash('error')})
}
})
// 处理登录请求(可能来自登录界面中的表单)
router.post('/login', (req, res) => {
AV.User.logIn(req.body.emailOrPhone, req.body.password).then((user) => {
user.set('lastLoginIP', req.headers['x-real-ip'])
user.save()
res.saveCurrentUser(user) // 保存当前用户到 Cookie
res.redirect('/users/profile') // 跳转到个人资料页面
}, (error) => {
//登录失败,跳转到登录页面
console.log(error.code)
req.flash('error', error.code)
return res.redirect('/users/login')
})
})
<!DOCTYPE HTML>
<html>
<head>
<title>登陆</title>
</head>
<body>
<% if (flash) { %>
<p><%= flash.message %></p>
<% } %>
<form action="/users/login" method="post">
<label>用户名/邮箱:</label>
<input type="text" name="emailOrPhone" autocomplete="on" placeholder="用户名/邮箱">
<label>密码:</label>
<input type="password" name="password" autocomplete="off" placeholder="密码">
<input type="submit" value="登陆"/>
</form>
</body>
</html>
const express = require('express')
const cookieParser = require('cookie-parser')
const cookieSession = require('cookie-session')
const AV = require('leanengine')
const flash = require('flash')
app.use(AV.Cloud.CookieSession({ secret: 'my secret', maxAge: 3600000, fetchUser: true }))
app.use(cookieSession({ name: 'session', keys: ['key1', 'key2'] }))
app.use(flash())
代码如上所述,看过文档中关于session的描述了,但是还是没能配置成功。
现在beta版本实际使用还是有一些问题的,能不能创建一个稳定版本的分支,方便使用。
现在似乎改为了这个AV.Promise._isPromisesAPlusCompliant = false;
和升级指南的,不一样。升级指南的会提示 undefined。
https://leancloud.cn/docs/leanengine_upgrade_3.html
美国节点项目
`xirtam:node xirtam$ git clone [email protected]:leancloud/node-js-getting-started.git
Cloning into 'node-js-getting-started'...
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
`
lean new返回401
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.