小编use*_*165的帖子

防止没有确认电子邮件的用户登录ASP.NET MVC Web API身份(OWIN安全性)

我有一个MVC和一个Web API项目,使用ASP.NET MVC Web API身份(OWIN安全性)进行身份验证.

我在Register功能正常的函数中添加了电子邮件确认,但我不确定如何emailConfirmed = true在登录之前检查是否因为Web API标识上没有显式的登录功能,这是隐含的.

我知道微软有充分的理由深度封装授权功能,但是没有办法实现这一目标吗?

请指教.

这是我的注册功能:

[AllowAnonymous]
[Route("Register")]
 public async Task<IHttpActionResult> Register(RegisterBindingModel model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

        IdentityResult result = await UserManager.CreateAsync(user, model.Password);

        if (!result.Succeeded)
        {
            return GetErrorResult(result);
        }

        try
        {
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));

            var email …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc login asp.net-web-api asp.net-identity

6
推荐指数
1
解决办法
1211
查看次数

从文件名中删除非法字符,但保留空格

我有以下代码行可从文件名中删除非法字符:

str= str.replace(/([^a-z0-9]+)/gi, '-');
Run Code Online (Sandbox Code Playgroud)

效果很好,但它也删除了空格,我如何才能只删除非法字符却留出空格?

javascript regex

6
推荐指数
3
解决办法
6449
查看次数

带有图标组件的按钮

我有一个<Button />组件和一个<Icon/>组件。

我尝试实现一个带有图标的按钮。

Button.jsx故事:

import React from "react";
import { storiesOf } from "@storybook/react";
import Button from "../components/Button";
import Icon from "../components/Icon/Index";
import { iconTypes } from "../components/Icon/Index";

storiesOf("Button/Primary", module)
    .add("With icon", () => (
        <Button><Icon type={iconTypes.arrowRight}/></Button>
    ))
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我希望带有图标的按钮的 api 是-

<Button icon={icons.arrow}>Click Me</Button>
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Icon.jsx故事:

import React from "react";
import { storiesOf } from "@storybook/react";
import Icon from "../components/Icon/Index";
import { iconTypes } from "../components/Icon/Index";    

storiesOf("Icon", module)
    .add("Arrow Right", () => …
Run Code Online (Sandbox Code Playgroud)

reactjs

6
推荐指数
1
解决办法
3万
查看次数

通过dompdf用codeigniter生成的pdf电子邮件

我有一个从Codeigniter中的html视图生成的PDF,现在我想将其发送到我的电子邮件中,但是我遇到的麻烦是它显示中有一个字符串,$pdf但是在我的电子邮件中发送时为空。这是整个Codeigniter函数。

public function generatePDF()
{
    require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');

    $dompdf = new Dompdf();
    $msg = $this->load->view('credit_agreement_view', '', true);
    $html = mb_convert_encoding($msg, 'HTML-ENTITIES', 'UTF-8');
    $dompdf->load_html($html);
    $paper_orientation = 'Potrait';
    $dompdf->set_paper($paper_orientation);

    // Render the HTML as PDF
    $dompdf->render();
    $pdf = $dompdf->output();

    // sending the pdf to email
    $this->load->library('email');
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.gmail.com';
    $config['smtp_port']    = '465';
    $config['smtp_timeout'] = '7';
    $config['smtp_user']    = 'support@aurorax.co';
    $config['smtp_pass']    = '#######';
    $config['charset']    = 'utf-8';
    $config['newline']    = "\r\n";
    $config['mailtype'] = 'text'; // or html
    $config['validation'] = TRUE; // bool whether …
Run Code Online (Sandbox Code Playgroud)

php pdf codeigniter dompdf

5
推荐指数
1
解决办法
1903
查看次数

如何使用JavaScript在特定情况下加载特定的css文件?

我想要:

// Display loader spinner
// Check if ID or Class exist in HTML Page
// If ID or Class are found, load a specific css file
// Display HTML PAGE
Run Code Online (Sandbox Code Playgroud)

可能吗?

javascript

5
推荐指数
1
解决办法
117
查看次数

$ .ajaxSetup不起作用

我有以下功能来设置我的AJAX请求的标头:

self.authenticate = function () {
    self.token = sessionStorage.getItem(tokenKey);
    var headers = {};

    if (self.token) {
        headers.Authorization = 'Bearer ' + self.token;
        $.ajaxSetup({
            headers: headers
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用,当我检查开发人员收费(F12)或Fiddler中的标头时,我没有看到那里的custon标头,但是当我在请求上设置标头而不是通过ajaxSetup它完美地工作时.

authenticate在布局页面中调用这些函数:

$(document).ready(function () {
     var avm = new AuthenticationViewModel();
     avm.authenticate();
});
Run Code Online (Sandbox Code Playgroud)

self.token不是null.

例如,对于此请求:

self.getUsers = function (callback) {
    $.get("../API/Users/GetUsers/",callback);
}
Run Code Online (Sandbox Code Playgroud)

这些是标题: 在此输入图像描述

我错过了什么?

javascript ajax request-headers

5
推荐指数
2
解决办法
2136
查看次数

根据数组值获取子数组

我有一个categories数组:

{id: 1, catName: "test", subCategories: Array(2)}
Run Code Online (Sandbox Code Playgroud)

我需要检索的subCategories基于阵列idcategory

这将返回整个category对象,如何更改它以仅返回subCategories数组?

  const subCategories = categoriesWithSub.filter(category => {
    return category.id === departments.catId;
  });
Run Code Online (Sandbox Code Playgroud)

javascript arrays object

5
推荐指数
1
解决办法
70
查看次数

想要将负数转换为正数

我有一个下面的查询,我已在过程中使用此查询,并想将一个数字转换为正数,因为现在它是负数。

 UPDATE SHIPMENT
        SET TOTAL_SHIP_UNIT_COUNT = (
          CASE
            WHEN V_SHIP_UNIT_COUNT > v_diff_cost
            THEN V_SHIP_UNIT_COUNT - v_diff_cost
            ELSE v_diff_cost       - V_SHIP_UNIT_COUNT
          END)
        WHERE SHIPMENT_GID = v_shipment_id;
        COMMIT;
Run Code Online (Sandbox Code Playgroud)

在此查询中,v_diff_cost的值为负,因此在执行( V_SHIP_UNIT_COUNT - v_diff_cost)操作时会将两个值相加,因此,如果我将v_diff_cost值转换为正,则在减去时将得到正确的结果。

假设V_SHIP_UNIT_COUNT值是33且v_diff_cost value是-10,则在这种情况下,它应按原样执行操作,33-10 = 23但应按原样执行操作33-(-10)= 43,这不应发生。

请帮助我。谢谢

sql-server

4
推荐指数
1
解决办法
2785
查看次数

Yesod,withAsync

我是Haskell和Yesod的新手,我正在尝试使用该Control.Concurrent.Async模块来做异步.(代码基于:https://hackage.haskell.org/package/async-2.1.1/docs/Control-Concurrent-Async.html#v : withAsync)

quizWidget = do
   --Get first question   
    withAsync (showQuizItem 1 1 ) $ \qi -> do
    withAsync (showScoreboard)    $ \sb -> do

    quizItem <- wait (qi)
    scoreboard <- wait (sb)

    toWidget $(hamletFile "hamlet/quiz.hamlet")
Run Code Online (Sandbox Code Playgroud)

但是这会产生以下错误:

"使用'toWidget'时没有(MonadWidget IO)的实例".

所以问题是我做错了什么?

haskell asynchronous yesod

4
推荐指数
1
解决办法
144
查看次数

必须匹配Source和Log属性

当我尝试启动该服务时,我收到以下错误:

服务无法启动.System.ArgumentException:源'Bar source'未在日志'Bar2'中注册.(它在日志'Bar source'中注册.)"Source和Log属性必须匹配,或者您可以将Log设置为空字符串,它将自动匹配Source属性.在System.Diagnostics.EventLogInternal.在Bar.Service1的System.Diagnostics.EventLog.WriteEntry(String message)上的System.Diagnostics.EventLogInternal.WriteEntry(String message,EventLogEntryType type,Int32 eventID,Int16 category,Byte [] rawData)中的VerifyAndCreateSource(String sourceName,String currentMachineName) C:\ Program Files(x86)\ Bar中的.writeToLog(String msg) - 用于AP:\ Service1.vb:C:\ Program Files(x86)中Bar.Service1.OnStart(String [] args)的第292行栏 - 用于APPS\Service1.vb:第37行,System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(对象状态)

有谁知道什么会导致这个问题?我Bar2在代码中没有提到,程序文件中的文件夹被称为"Bar2",但我将其更改为"Bar".

请指教!

这是WriteToLog功能:

Private Sub writeToLog(ByVal msg As String)
    Dim evtLog As New EventLog
    If Not Diagnostics.EventLog.SourceExists("Bar") Then
        Diagnostics.EventLog.CreateEventSource("Bar", "Log of Bar")
    End If
    evtLog.Source = "Bar"
    evtLog.Log = "Log of Bar"
    evtLog.WriteEntry(msg)
End Sub
Run Code Online (Sandbox Code Playgroud)

.net

4
推荐指数
2
解决办法
1392
查看次数