예제 #1
0
        /// <summary>
        /// 检查图片合法性
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public bool ImageCheck(string image)
        {
            string url = "http://ai.qiniuapi.com/v3/image/censor";


            const string path    = "/v3/image/censor";
            string       bodyStr = "{ \"data\": { \"uri\": \"" + image + "\" } ,\"params\": {\"scenes\": [\"pulp\", \"terror\", \"politician\"]} }";

            string data  = QiniuTokenUtility.GetData(post, path, rawQuery, host, contentType, bodyStr);
            string token = QiniuTokenUtility.GetQiniuToken(data);

            HttpContent httpContent = new StringContent(bodyStr, Encoding.UTF8);

            httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            using (HttpClient client = new HttpClient()) {
                client.DefaultRequestHeaders.Add("Authorization", token);
                HttpResponseMessage respon     = client.PostAsync(url, httpContent).Result;
                var           rs               = respon.Content.ReadAsStringAsync().Result;
                CheckResponse imageCheckRespon = JsonConvert.DeserializeObject <CheckResponse>(rs);

                if (imageCheckRespon.Result.Suggestion != "pass")
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public async void WhenLoginWithValidCredentials_Cookie_ShouldGetSuccessAndCookie()
        {
            var response = await syno.Login(TestConfig.Account, TestConfig.Password, session);

            CheckResponse.HasSucceeded(response);
            Assert.Null(response.Sid);
        }
예제 #3
0
        public System.IO.Stream Check(string hash)
        {
            try
            {
                if (!App.credentials.IsAllow("check"))
                {
                    return(null);
                }

                BtcAddressEntity model = new BtcAddressModel(App.db).getByHash(hash);
                if (model == null)
                {
                    return(null);
                }

                string result = new CheckResponse(model, App.settings).toJson();

                byte[] resultBytes = Encoding.UTF8.GetBytes(result);
                WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
                return(new MemoryStream(resultBytes));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #4
0
    public async Task ChangePassword_Should_Return_BadRequest_If_OldPassword_Does_Not_Match_User_Password()
    {
        // Arrange
        var user = Builder <ApplicationUser> .CreateNew()
                   .With(u => u.UserName = "******")
                   .With(u => u.Email    = "*****@*****.**")
                   .Build();

        var userManager = Host.Services.GetRequiredService <UserManager <ApplicationUser> >();

        var createdUser = await userManager.CreateAsync(user, "Password.1!");

        var changePasswordModel = Builder <ChangePasswordModel> .CreateNew()
                                  .With(cu => cu.OldPassword = "******")
                                  .With(cu => cu.NewPassword = "******")
                                  .Build();

        // Act
        var apiResponse =
            await Client.PutAsync($"/api/users/{user.Id}/changePassword", new JsonContent(changePasswordModel));

        // Assert
        apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        CheckResponse.Failure(response);
    }
        public async Task Get_Todo_Lists_Should_Return_All_Todo_Lists_For_Specified_User_From_Database()
        {
            // Arrange
            var context = _host.Services.GetRequiredService <DatabaseContext>();

            var user = await context.Users.Where(u => u.Email == "*****@*****.**").FirstOrDefaultAsync();

            context.TodoLists.RemoveRange(context.TodoLists.ToList());

            var todoLists = Builder <TodoList> .CreateListOfSize(10).All().With(tl => tl.Id = Guid.NewGuid()).With(tl => tl.CreatedBy = user.Id).Build();

            var todoListsNotBelongToTheUser = Builder <TodoList> .CreateListOfSize(10).All()
                                              .With(tl => tl.Id = Guid.NewGuid()).With(tl => tl.CreatedBy = Guid.NewGuid().ToString()).Build();

            context.TodoLists.AddRange(todoLists);
            context.TodoLists.AddRange(todoListsNotBelongToTheUser);

            context.SaveChanges();

            // Act
            var apiResponse = await _client.GetAsync($"/api/todoLists");

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <IEnumerable <TodoListResponseModel> > >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Succeded(response);
            response.Result.Should().HaveCount(10);
        }
예제 #6
0
파일: Checks.cs 프로젝트: FreeReign/forkuo
 public CheckPlus(int x, int y, int inactiveID, int activeID, bool initialState,
     int switchID, string name, int group, CheckResponse callback)
     : base(x, y, inactiveID, activeID, initialState, switchID)
 {
     this._Name = name;
     this._Group = group;
     this._Callback = callback;
     this._Param = null;
 }
 public CommandResponse <CheckResponse> CanUpdateOrRemove([FromRoute] int id_anexo)
 {
     return(this.TryCatch(() =>
     {
         var check = _anexoAplicacion.CheckCanUpdateOrRemove(id_anexo);
         var response = new CheckResponse {
             check = check
         };
         return _Response(data: response);
     }));
 }
예제 #8
0
        public CheckResponse Login([FromBody] WJUser user)
        {
            var res = new CheckResponse();

            if (user == null || CommonUtils.IsNullStr(user.UNO) || CommonUtils.IsNullStr(user.PW))
            {
                res.Msg       = "user schemas is error";
                res.ErrorItem = "user";
                return(res);
            }
            using (WJCenterEntities ctx = new WJCenterEntities())
            {
                string uno  = user.UNO.Split('|')[0];
                string guid = user.UNO.Split('|')[1];
                var    item = ctx.WJUsers.Where(p => p.UNO == uno).FirstOrDefault();
                if (item == null)
                {
                    res.Msg       = "该工号不存在";
                    res.ErrorItem = "username";
                    return(res);
                }
                if (item.ErrorStatus > 0)
                {
                    res.Msg       = "该工号已冻结";
                    res.ErrorItem = "username";
                    return(res);
                }
                //后期密码要加密
                if (item.PW != user.PW)
                {
                    res.Msg       = "密码错误";
                    res.ErrorItem = "pwd";
                    return(res);
                }
                if (!WebApiApplication.VS.VerCodeDic.ContainsKey(guid))
                {
                    res.Msg       = "验证码已过期,请重新验证";
                    res.ErrorItem = "validator";
                    return(res);
                }
                if (!WebApiApplication.VS.VerCodeDic[guid].IsCorrect)
                {
                    res.Msg       = "验证码错误";
                    res.ErrorItem = "validator";
                    return(res);
                }
                //校验通过,登录成功并记录状态
                res.State = 1;
                res.Msg   = "/Views/main.html";

                return(res);
            }
        }
        public async Task Login_Should_Return_User_Informations_And_Token()
        {
            // Arrange

            // Act
            var apiResponse = await _client.GetAsync("/api/WeatherForecast");

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <IEnumerable <WeatherForecastResponseModel> > >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Succeded(response);
            response.Result.Should().HaveCount(5);
        }
예제 #10
0
    public async Task Login_Should_Return_User_Information_And_Token()
    {
        // Arrange

        // Act
        var apiResponse = await Client.GetAsync("/api/WeatherForecast");

        // Assert
        var response = await ResponseHelper.GetApiResultAsync <IEnumerable <WeatherForecastResponseModel> >(apiResponse);

        CheckResponse.Succeeded(response);
        response.Result.Should().HaveCount(5);
    }