Last major update: 25.08.2020
- Что такое авторизация/аутентификация
- Где хранить токены
- Как ставить куки ?
- Процесс логина
- Процесс рефреш токенов
- Кража токенов/Механизм контроля токенов
| // First we have our component which takes data and callback functions as props | |
| const ProductDetails = ({ selectedColor, selectedSize, setSelectedColor, setSelectedSize }) => { | |
| return ( | |
| <div> | |
| <p>Selected color is: {selectedColor}</p> | |
| <p>Selected size is: {selectedSize}</p> | |
| <button onClick={() => setSelectedSize(64)}> set selected size 64</button> | |
| <button onClick={() => setSelectedColor("green")}> set selected color to green </button> | |
| </div> | |
| ); |
| from bs4 import BeautifulSoup | |
| import requests | |
| import re | |
| import urllib2 | |
| import os | |
| import argparse | |
| import sys | |
| import json | |
| # adapted from http://stackoverflow.com/questions/20716842/python-download-images-from-google-image-search |
This is a rough guide to setting up browser testing through Selenium on Windows Subsystem for Linux (WSL), aka Bash on Ubuntu on Windows. It assumes the following environment:
The coding project folders are stored in the main Windows filing hierarchy and accessed via dev/mnt, but that makes no real difference to development and testing other than making it possible to edit the code using a GUI based editor within Windows.
The problem with browser testing in WSL is that it relies on opening and controlling a web browser, and browsers don’t work on WSL at present as it deliberately doesn’t include X Windows or some other GUI manager - it’s meant to be command line after all. So while you can apt-get firefox, trying to actually run it isn’t going to work.
| sudo apt-get update | |
| sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y | |
| sudo apt-get install libfreetype6 libfreetype6-dev -y | |
| sudo apt-get install libfontconfig1 libfontconfig1-dev -y | |
| cd ~ | |
| export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64" | |
| wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2 | |
| sudo tar xvjf $PHANTOM_JS.tar.bz2 | |
| sudo mv $PHANTOM_JS /usr/local/share | |
| sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin |
| # ... | |
| # config/deploy.rb, config/deploy/production.rb etc. | |
| # contents omitted | |
| ### | |
| # example: add backup task prior to deploy | |
| namespace :deploy do | |
| before :deploy, "db:dump" | |
| end |
| const stateIdLens = propLens('id') | |
| const stateTokenLens = propLens('token') | |
| let setCurrentUserId = (state, action) => set(idLens, action.payload.result, state) | |
| let setCurrentUserToken = (state, action) => set(tokenLens, action.payload.token, state) | |
| compose(setCurrentUserId, setCurrentUserToken) | |
When using react-rails for an internationalized app it makes a lot of sense to use i18n-js for translations, so that you can reuse the the strings from your rails app's .yml files (and all the tooling & services that exist around that).
When you use the prerender feature of react-rails you face 2 problems:
translation.js & i18n.js from i18n-js need to be loaded inside the server-side JS prerendering processes, which is achieved by loading them inside the components.js.locale of each HTTP request. This is done by adding a custom renderer and using the before_render hook to configure i18n-js accordingly for each render call.| function mapValues(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| result[key] = fn(obj[key], key); | |
| return result; | |
| }, {}); | |
| } | |
| function pick(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| if (fn(obj[key])) { |
| // takes a {} object and returns a FormData object | |
| var objectToFormData = function(obj, form, namespace) { | |
| var fd = form || new FormData(); | |
| var formKey; | |
| for(var property in obj) { | |
| if(obj.hasOwnProperty(property)) { | |
| if(namespace) { |