我试图为用户建立确认电子邮件地址,以验证他们的电子邮件是真实的.我应该用什么软件包来确认用户的电子邮件地址.到目前为止我使用猫鼬和表达
代码示例
var UserSchema = new mongoose.Schema({
email: { type: String, unique: true, lowercase: true }
password: String
});
var User = mongoose.model('User', UserSchema);
app.post('/signup', function(req, res, next) {
// Create a new User
var user = new User();
user.email = req.body.email;
user.password = req.body.password;
user.save();
});
Run Code Online (Sandbox Code Playgroud)
在app.post代码中,如何确认用户的电子邮件地址?
我正在使用https://github.com/auth0/socketio-jwt将用户连接到我的node.js/socket.io服务器,我正在使用一次往返
我现在的问题是,无论何时用户登录IOS部分,socket.connect()都不一致,我的理论是,即使在socket.connect()被调用之前,令牌还没有准备就绪.
我正在为我的Socket.io类使用Singleton设计,因为许多人指出了这一点.
这是该SocketManager.swift部分的代码
import SocketIO
class SocketIOManager: NSObject {
static let sharedInstance = SocketIOManager()
var socket = SocketIOClient(socketURL: URL(string: mainURL)!, config: [.log(false), .compress, .connectParams(["token": getToken()])]) // getToken() I got it from other file which is Constant.Swift
func establishConnection() {
socket.connect()
}
func closeConnection() {
socket.disconnect()
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用KeychainAccess存储令牌,Constant.Swift文件存储所有全局变量和函数,以便我可以在任何Swift文件上调用它.
Constant.Swift
import Foundation
import KeychainAccess
let keychain = Keychain(server: "www.example.com", protocolType: .https)
func getToken() -> String {
if let token = …Run Code Online (Sandbox Code Playgroud) 我打算创建一条路线,用户可以将其他用户添加为他/她的朋友,这样他们一旦成为朋友就可以互相聊天.
因此,基本上一旦用户A向用户B发送了请求,用户B将通过以下方式获得有关请求的实时通知 socket.io
现在的问题是,我无法想出如何实现上述方案的自己的解决方案,据我所知,我应该创建两条路线GET,POST
我正在使用mongoose进行数据库查询,插入,更新和删除
这是我的代码
// GET route for getting the user's information -- Simple route
router.get('/users/:facebook_name', function(req, res) {
User.findOne(facebook_name, function(err, user) {
if (!user) {
res.json({message: "Couldn't find a user by that name"});
return;
}
res.json(user);
});
});
// POST route for adding a friend
router.post('/friendships/create/:facebook_name', ensureAuthenticated, function(req, res) {
// What should i put in this route to make the adding a friend feature works?
User.findOneAndUpdate(facebook_name, function(err, user) {
if (user) {
res.json({message: …Run Code Online (Sandbox Code Playgroud) 我创建了一个表视图,然后从那里开始说用户按下了一个单元格,它将转到detailItemView,但现在唯一的问题是每当用户在detailItemView中时,没有后退按钮,即使我已经嵌入了导航控制器
这是用户按下单元格后将执行segue的代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
var nav = segue.destinationViewController as! UINavigationController
var detailScene = nav.topViewController as! DetailViewController
// Pass the selected object to the destination view controller.
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.currentObject = objects?[row] as? PFObject
}
}
Run Code Online (Sandbox Code Playgroud)
故事板的屏幕截图:

编辑截图

我试着在下面做出答案,但仍然没有后退按钮
另一个截图,detailView控制器没有后退按钮

我明白什么是网格,基本上整行将有12个空格.
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
基本上上面的代码只是将空格划分为3个部分,但我不明白的是,什么是做偏移的重点?
<div class="col-lg-6 col-md-offset-3"></div>
Run Code Online (Sandbox Code Playgroud)
上面的代码到底是做什么的?
目前我正在尝试在api调用中更新两个不同的用户架构.
第一个模式记录在用户模式中,我们给它命名= Tom第二个模式是注册该应用程序的其他用户,我们给它命名= John
架构代码
schema.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');
var UserSchema = new Schema({
name: String,
username: { type: String, required: true, index: { unique: true }},
password: { type: String, required: true, select: false },
followers: [{ type: Schema.Types.ObjectId, ref: 'User'}],
following: [{ type: Schema.Types.ObjectId, ref: 'User'}],
followersCount: Number,
followingCount: Number
});
module.exports = mongoose.model('User', UserSchema);
Run Code Online (Sandbox Code Playgroud)
api名称是'/ follow /:user_id',我想要实现的是.每当用户Tom跟随John这样的其他用户时,Tom的跟随字段将被更新以及John的跟随者字段.
我当前的尝试(req.decoded.id是登录用户)
api.js
// The first way
apiRouter.post('/follow/:user_id', …Run Code Online (Sandbox Code Playgroud) 我的目标是在mongodb和redis的帮助下在node.js中构建一个简单的新闻源.它像twitter一样
因此,一旦用户A关注用户B,情况就非常简单.稍后用户的A新闻提要(主页)将显示用户B的活动,就像他发布的内容一样.
用户架构
const UserSchema = new Schema({
email: { type: String, unique: true, lowercase: true},
});
const followSchema = new Schema(
{
user: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
target: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
});
Run Code Online (Sandbox Code Playgroud)
目前我的用户架构的设计非常简单,当我跟随另一个用户时,我将创建Follow Schema对象
并且还有另一个模式,即后置模式
/* This is similar like the Tweet */
var PostSchema = new Schema({
// Own by the user
creator: { type: Schema.Types.ObjectId, ref: 'User' }
body: String,
});
Run Code Online (Sandbox Code Playgroud)
此架构供用户发布任何内容,类似于Twitter发布.
假设我跟随了一堆用户
{
user: 'me',
target: 'draco' …Run Code Online (Sandbox Code Playgroud) 如何查询虚拟字段,以便它在JSON响应中
const ItemSchema = mongoose.Schema({
name: String,
time: { type: Date, default: Date.now }
});
ItemSchema.virtual('timeleft').get(function() {
this.timeleft = 24
var currentTime = moment();
var timeStored = moment.utc(this.time).local().format();
this.timeleft -= currentTime.diff(timeStored, 'h');
});
Run Code Online (Sandbox Code Playgroud)
API调用
app.get('/getAllItems', function(req, res, next) {
Item.find({}, function(err, items) {
res.json(items);
});
});
Run Code Online (Sandbox Code Playgroud)
因此从技术上讲,响应将不包括虚拟时间段.我错过了什么吗?
[
{
name: "nike",
time: "21/2/22"
},
{
name: "adidas",
time: "21/2/22"
},
]
Run Code Online (Sandbox Code Playgroud) 目前,我有一个困惑,即对架构中的一系列项目进行分页。
因此从技术上讲,每个用户都有一个购物车,我想对购物车的商品进行分页。例如,假设购物车存储了 18 件商品。我想将购物车分页为仅 5 件商品。
这是架构
const UserSchema = new Schema({
email: { type: String, unique: true, lowercase: true},
cart: [{
type: Schema.Types.ObjectId, ref: 'Product'
}],
});
Run Code Online (Sandbox Code Playgroud)
这是路线
我目前的方法
router.get('/cart', (req, res, next) => {
User.findOne({ _id: req.user._id })
.populate({
path: 'cart',
options: { limit: 5 }
})
.exec((err, user) => {
res.render('order/cart', { user: user });
});
});
Run Code Online (Sandbox Code Playgroud)
我当前的方法肯定会将显示的商品从 18 件限制为仅 5 件,但这会产生一个新问题,现在我无法计算购物车的总价,因为它只限制每个请求 5 件商品。
我的目标是以编程方式显示View Controller
当前视图控制器
然后,如果某个事件被调用或某事,(API或Websocket)我想以编程方式调用这些视图
但我想先调用最后一个视图Controller,它应该位于第一个View控制器之上
从技术上讲,最后一个视图将具有
Transition is Cross Dissolve
Presentation is Over Current Context
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
node.js ×6
mongodb ×4
mongoose ×4
express ×3
ios ×3
swift ×3
socket.io ×2
css ×1
jwt ×1
mean-stack ×1
node-redis ×1
pagination ×1
redis ×1
segue ×1
uitableview ×1