Comments (2)
Database Action Scripts のバックアップ。
Login
function login(email, password, callback) {
//this example uses the "pg" library
//more info here: https://github.com/brianc/node-postgres
const bcrypt = require('bcrypt');
const postgres = require('pg');
postgres.connect(configuration.DATABASE_URL, function(err, client, done) {
if (err) return callback(err);
const query = `
select
users.id
, users.email
, users.password_digest
, users.subscribing
, members.id as member_id
, members.name
, members.joined_year
from
users
join members on users.member_id = members.id
where
users.email = $1
and users.password_digest is not null
`;
client.query(query, [email], function(err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
if (err || result.rows.length === 0) return callback(err || new WrongUsernameOrPasswordError(email));
const user = result.rows[0];
bcrypt.compare(password, user.password_digest, function(err, isValid) {
if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));
return callback(null, {
user_id: user.id.toString(),
name: user.name,
email: user.email,
email_verified: true,
user_metadata: {
livelog_email_notifications: user.subscribing,
},
app_metadata: {
joined_year: user.joined_year,
livelog_member_id: user.member_id,
},
});
});
});
});
}
Get User
function loginByEmail(email, callback) {
//this example uses the "pg" library
//more info here: https://github.com/brianc/node-postgres
const postgres = require('pg');
postgres.connect(configuration.DATABASE_URL, function(err, client, done) {
if (err) return callback(err);
const query = `
select
users.id
, users.email
, users.password_digest
, users.subscribing
, members.id as member_id
, members.name
, members.joined_year
from
users
join members on users.member_id = members.id
where
users.email = $1
and users.password_digest is not null
`;
client.query(query, [email], function(err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
if (err || result.rows.length === 0) return callback(err);
const user = result.rows[0];
return callback(null, {
user_id: user.id.toString(),
name: user.name,
email: user.email,
email_verified: true,
user_metadata: {
livelog_email_notifications: user.subscribing,
},
app_metadata: {
joined_year: user.joined_year,
livelog_member_id: user.member_id,
},
});
});
});
}
from livelog.
止めた。
from livelog.
Related Issues (20)
- メール本文の URL が Sendgrid の長い URL に変わっている HOT 1
- sentry-raven から sentry-ruby へのマイグレーション HOT 1
- Auth0::BadRequest: {"statusCode":400,"error":"Bad Request","message":"The connection does not exist.","errorCode":"i... HOT 1
- PayPal マネープールのサービス終了
- Upgrade Heroku Postgres HOT 1
- Stimulus やめたい
- プロフィール画像を更新しても以前の画像が表示される HOT 2
- Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated
- 非ログインユーザに対し、メンバーの古い名前が表示される HOT 2
- Auth0 と users テーブルの整合性チェックスクリプトを書く
- "ライブ名はすでに存在します" で CI がコケる HOT 3
- Terraform 使ってみる HOT 2
- 招待周りのイベントを Slack に通知する
- Slack::Web::Api::Errors::SlackError: invalid_blocks HOT 1
- ライブの開始日"時"を保存できるようにする
- ライブの公開状態とエントリー可能状態を分けられるようにする
- ライブ詳細ページを改善する HOT 1
- Auth0 周りの改善
- API 周りのドキュメントを整備する HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from livelog.