我想生成一个令牌并将其插入我的mysql数据库,这是当前的代码,我只是传递了' 123'。 mix phoenix.gen.secret可以生成随机字符串如何将它用于我的控制器?
def create(conn, %{"token" => token_params}) do
token_params = Map.merge(token_params, %{"value" => "123"})
changeset = Token.changeset(%Token{}, token_params)
case Repo.insert(changeset) do
{:ok, token} ->
conn
|> put_status(:created)
|> put_resp_header("location", token_path(conn, :show, token))
|> render("show.json", token: token)
{:error, changeset} ->
conn
|> put_status(:unprocessable_entity)
|> render(MyApp.ChangesetView, "error.json", changeset: changeset)
end
端
答案 0 :(得分:8)
您可以使用$filePath='[msi file path]'
$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = 'c:\{0}-{1}.log' -f 'nodejsInstall',$DataStamp
$MSIArguments = @(
"/i"
('"{0}"' -f $filePath)
"/qn"
"/norestart"
"/L*v"
$logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
,:crypto.strong_rand_bytes/1
uses internally:
mix phoenix.gen.secret
答案 1 :(得分:2)
如何使用Ecto?
Ecto.UUID.generate |> binary_part(16,16)
答案 2 :(得分:1)
Phoenix有内置的Phoenix.Token
模块来生成令牌,这样您就可以验证令牌的真实性,甚至无需访问数据库。例如,如果要为特定用户生成令牌:
# Generate a token for a given user_id
user_id = # get id of current user
token = Phoenix.Token.sign(MyApp.Endpoint, "user", user_id)
# Later, verify and decode the token,
# and assert that it matches the expected user_id
user_id = # get id of current user
{:ok, ^user_id} = Phoenix.Token.verify(MyApp.Endpoint, "user", token)