Beispiel #1
0
        public int xxxx()
        {
            DataBaseEntities db = new DataBaseEntities();
            var i = db.AspNetUsers.Count();

            HttpContext.Current.Application.Lock();
            int result = (int)(HttpContext.Current.Application["count"] ?? 0);
            HttpContext.Current.Application["count"] = ++result;
            HttpContext.Current.Application.UnLock();

            return result;
        }
Beispiel #2
0
        public string dddd()
        {
            DataBaseEntities db = new DataBaseEntities();
            db.tb_JiuYouQuan.ToList().ForEach(u => {
                if (u.Images.IndexOf("http://hdy.awblob.com")==0)
                {
                    DataBaseEntities db1 = new DataBaseEntities();
                    var obj = db1.tb_JiuYouQuan.Single(g => g.id == u.id);
                    db1.tb_JiuYouQuan.Remove(obj);
                    db1.SaveChanges();
                }

            });
            return "zhong";
        }
Beispiel #3
0
 public IHttpActionResult latest(int type, int PageSize = 10, int PageIndex = 0)
 {
     DataBaseEntities db = new DataBaseEntities();
     var result = db.tb_JiuYouQuan.Include("AspNetUsers").OrderByDescending(u => u.AddDate).Skip(PageSize * PageIndex).Take(PageSize).ToList().Select(u => new
     {
         u.AddDate,
         u.Description,
         u.id,
         Images = u.Images == "" ? new String[] { } : u.Images.Split(';').ToList().Select(g => CacheObjectHelper.SystemConfig.url_blob + g),
         u.SingleHeight,
         u.SingleWidth,
         Portrait = CacheObjectHelper.SystemConfig.url_blob + u.AspNetUsers.Portrait,
         u.AspNetUsers.NickName
     });
     return Json(new ResponseMessageModel(result));
 }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <returns></returns>
        public async Task<IHttpActionResult> Post()
        {
            try
            {
                if (!HttpContext.Current.Request.Form.HasKeys())
                {
                    CommonRequestHelper.ThrowErrorMessage("上传失败");
                }

                DataBaseEntities db = new DataBaseEntities();
                OSSHelper blob = new OSSHelper(AIHE.WebApi.Helpers.UtilityString.BlobString.YiQiHeHe);

              
                switch (HttpContext.Current.Request.Files.Count)
                {
                    case 0:
                        {
                            var news0 = new tb_JiuYouQuan
                            {
                                AddDate = UtilityHelper.getNow(),
                                Description = HttpContext.Current.Request.Form["content"],
                                id = Guid.NewGuid().ToString(),
                                IsHot = false,
                                Islegal = true,
                                SingleHeight = 0,
                                SingleWidth = 0,
                                UserId = User.Identity.GetUserId(),
                                Images = ""
                            };
                            db.tb_JiuYouQuan.Add(news0);
                            db.SaveChanges();
                       
                            return Json(new ResponseMessageModel(true));


                        }
                      
                        break;
                    case 1:
                        //只有一个文件
                        #region
                        string fileOrginalFile = HttpContext.Current.Server.MapPath("~/MyUpload/" + Guid.NewGuid().ToString() + ".jpg");

                        HttpContext.Current.Request.Files[0].SaveAs(fileOrginalFile);
                        Image pic = Image.FromFile(fileOrginalFile);//strFilePath是该图片的绝对路径
                        int intWidth = pic.Width;//长度像素值
                        int intHeight = pic.Height;//高度像素值 
                        int newWidth = intWidth;
                        int newHeight = intHeight;
                        string fileResizedName = HttpContext.Current.Server.MapPath("/MyUpload/" + Guid.NewGuid().ToString() + ".jpg");
                        string saveFileName = Guid.NewGuid().ToString();
                          blob.UploadFile(fileOrginalFile, saveFileName + "-big");


                        if (intWidth > 135 || intHeight > 135)
                        {
                            using (var imageFactory = new ImageFactory(preserveExifData: true))
                            {


                                if (intWidth > intHeight)
                                {
                                    newWidth = 135;
                                    newHeight = (int)(Convert.ToDouble(intHeight) / Convert.ToDouble(intWidth) * 135);
                                }
                                else
                                {
                                    newHeight = 135;
                                    newWidth = (int)(Convert.ToDouble(intWidth) / Convert.ToDouble(intHeight) * 135);
                                }

                                System.Drawing.Size size = new System.Drawing.Size(newWidth * 2, newHeight * 2);
                                imageFactory.Load(fileOrginalFile).Resize(size).Save(fileResizedName);
                            }
                              blob.UploadFile(fileResizedName, saveFileName);  //缩略图应该是同步程序
                        }
                        else
                        {
                              blob.UploadFile(fileOrginalFile, saveFileName);   //缩略图应该是同步程序
                        }

                        var news1 = new tb_JiuYouQuan
                        {
                            AddDate = UtilityHelper.getNow(),
                            Description = HttpContext.Current.Request.Form["content"],
                            id = Guid.NewGuid().ToString(),
                            Images = saveFileName,
                            IsHot = false,
                            Islegal = true,
                            SingleHeight = newHeight,
                            SingleWidth = newWidth,
                            UserId = User.Identity.GetUserId()
                        };
                        pic.Dispose();
                        File.Delete(fileOrginalFile);

                        File.Delete(fileResizedName);
                        db.tb_JiuYouQuan.Add(news1);
                        db.SaveChanges();
                        return Json(new ResponseMessageModel(true));

                    //删除文件

                        #endregion

                    default:
                        List<string> newsFiles = new List<string>();
                        for (var i = 0; i < HttpContext.Current.Request.Files.Count; i++)
                        {
                            var savedName = Guid.NewGuid().ToString();
                            var fileCropName = HttpContext.Current.Server.MapPath("/MyUpload/" + Guid.NewGuid().ToString() + ".jpg");
                            var orginal = HttpContext.Current.Server.MapPath("~/MyUpload/" + Guid.NewGuid().ToString() + ".jpg");
                            HttpContext.Current.Request.Files[i].SaveAs(orginal);
                              blob.UploadFile(orginal, savedName + "-big");

                            using (var imageFactory = new ImageFactory(preserveExifData: true))
                            {
                                // Do your magic here
                                System.Drawing.Size size = new System.Drawing.Size(70 *2, 70*2);
                                ResizeLayer resize = new ResizeLayer(size, ResizeMode.Crop);
                                imageFactory.Load(orginal).Resize(resize).Save(fileCropName);
                            }
                            bool flagCrop =   blob.UploadFile(fileCropName, savedName);

                            if (flagCrop)
                            {
                                newsFiles.Add(savedName);

                            }
                            File.Delete(orginal);

                            File.Delete(fileCropName);

                        }

                        if (newsFiles.Count == 0)
                        {

                            CommonRequestHelper.ThrowErrorMessage("上传失败");
                        }
                       


                            var newsMultiple = new tb_JiuYouQuan
                            {
                                AddDate = UtilityHelper.getNow(),
                                Description = HttpContext.Current.Request.Form["content"],
                                id = Guid.NewGuid().ToString(),
                                Images = string.Join(";", newsFiles),
                                IsHot = false,
                                Islegal = true,
                                SingleHeight = 0,
                                SingleWidth = 0,
                                UserId = User.Identity.GetUserId()
                            };
                            db.tb_JiuYouQuan.Add(newsMultiple);
                            db.SaveChanges();

                       

                              return Json(new ResponseMessageModel(true));
                      

                        break;

                }




            }

            catch (Exception ex)
            {
                
                CommonRequestHelper.ThrowErrorMessage("上传失败");
                return null;
            }
        }
Beispiel #5
0
        public async Task<IHttpActionResult> ProfilePortraitChange([FromBody] DT_Name model)
        {
            DataBaseEntities db = new DataBaseEntities();
            if (db.AspNetUsers.Any(u=>u.NickName == model.name))
            {
                return Json(new
                {
                    Code = 10000,
                    Detail = new {
                       IsValide = false
                    
                    } 
                });
            }

            var user = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name);
            user.NickName = model.name;
            db.SaveChanges();
            return Json(new
            {
                Code = 10000,
                Detail = new
                {
                    IsValide = true,
                    name = model.name

                } 
            });



        }
Beispiel #6
0
 public async Task<IHttpActionResult> ProfilePortraitChange([FromBody] DT_Portrait model)
 {
     DataBaseEntities db = new DataBaseEntities();
     var UserId = User.Identity.GetUserId();
     var user = db.AspNetUsers.Single(u => u.Id == UserId);
     user.Portrait = model.image;
     db.SaveChanges();
     user = db.AspNetUsers.Single(u => u.Id == UserId);
     return Json(new
     {
         Code = 10000,
         Detail = new
         {
             Portrait = CacheObjectHelper.SystemConfig.url_blob + user.Portrait
         }
     });
 }
Beispiel #7
0
        public async Task<IHttpActionResult> PasswordReset([FromBody] DT_Login model)
        {
            if (!UtilityHelper.VerifyMobileCode(model.Mobile, model.Code, true))
            {
                return Json(new { Code = 1, Message = "验证码错误或已经失效" });
            }
            DataBaseEntities db = new DataBaseEntities();
            var user = db.AspNetUsers.SingleOrDefault(u => u.MyMobilePhone == model.Mobile);
            if (user == null)
            {
                return Json(new { Code = 1, Message = "没有该手机号码" });
            }
            string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
            IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, model.Password);

            if (!passwordChangeResult.Succeeded)
            {
                return Json(new { Code = 1, Message = "修改密码错误" });
            }



            return Json(new { Code = 10000, Detail = true });

        }
Beispiel #8
0
        private IHttpActionResult  getLoginResult(string UserName, string Password)
        {
            DataBaseEntities db = new DataBaseEntities();
            string grant_type = "password";
            ASCIIEncoding encoding = new ASCIIEncoding();
            string postData = "grant_type=" + grant_type;
            postData += ("&password="******"&username="******"WebApiTokenAddress"]);
            //     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost:49445/token");
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            // Get response
            HttpWebResponse myResponse = null;

            try
            {
                myResponse = (HttpWebResponse)myRequest.GetResponse();
            }
            catch (WebException ex)
            {
                if (ex.Message.Contains("400"))
                {
                    return Json(new
                    {
                        Code = 1,
                        Message = "手机号码或密码错误"
                    });
                }
                else
                {
                    return Json(new
                    {
                        Code = 1,
                        Message = "网络访问错误"
                    });
                }
            }



            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
            string content = reader.ReadToEnd();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(content);
            string username = json["userName"].ToString();
            var myuser = db.AspNetUsers.Single(u => u.UserName == username);

            return Json(new ResponseMessageModel(new
            {
                token = json["access_token"].ToString(),
                IsValid = true,
                expired = json[".expires"].ToString(),
                Profile = new
                {
                    myuser.Sex,
                    NickName = myuser.NickName ?? "无名",
                    myuser.Id,
                    Portrait  = CacheObjectHelper.SystemConfig.url_blob + myuser.Portrait
                }
            }));


           

        }
Beispiel #9
0
        public async Task<IHttpActionResult> VcodeSendSMS(string m)
        {
            if (UtilityHelper.ConstVar.testAccount.Any(u => u == m))
            {
                return Json(new
                {
                    Code = 10000,
                    Detail = new { }
                });
            }
            if (!UtilityHelper.IsMobilePhone(m))
            {
                return Json(new
                {
                    Code = 1,
                    Message = "手机格式不正确"
                });
            }

            Random ran = new Random();
            int RandKey = ran.Next(1000, 9999);

            try
            {

                string mobile = m,
                message = "验证码:" + RandKey.ToString() + " ,两分钟内有效【喝喝】",
                username = ConfigurationManager.AppSettings["SMSUsername"],
                password = ConfigurationManager.AppSettings["SMSKey"],
                url = ConfigurationManager.AppSettings["SMSUrl"];
                byte[] byteArray = Encoding.UTF8.GetBytes("mobile=" + mobile + "&message=" + message);
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
                string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(username + ":" + password));
                webRequest.Headers.Add("Authorization", auth);
                webRequest.Method = "POST";
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;

                Stream newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.Default);
                string Message = php.ReadToEnd();
            }
            catch
            {
                return Json(new
                {
                    Code = 1,
                    Message = "验证码服务器有误"
                });
            }

            DataBaseEntities db = new DataBaseEntities();

            var verify = new cm_SMS_Verify
            {
                Id = Guid.NewGuid().ToString(),
                Code = RandKey,
                CreateDate = UtilityHelper.getNow(),
                Mobile = m
            };

            db.cm_SMS_Verify.Add(verify);
            db.SaveChanges();

            return Json(new
            {
                Code = 10000,
                Detail = new
                {

                }
            });
        }
Beispiel #10
0
 public async Task<IHttpActionResult> VcodeVerifySMS(string mp, int vcode)
 {
     if (UtilityHelper.VerifyMobileCode(mp, vcode, false))
     {
         DataBaseEntities db = new DataBaseEntities();
         return Json(new
         {
             Code = 10000,
             Detail = db.AspNetUsers.Any(u => u.MyMobilePhone == mp)
         });
     }
     else
     {
         return Json(new
         {
             Code = 1,
             Message = "验证码不正确"
         });
     }
 }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();

            ApplicationUser user = null ;
            DataBaseEntities db = new DataBaseEntities();
            if (context.UserName.First().ToString() == UtilityHelper.ConstTokenPrefix.MobilePassword)
            {

                var aspnetuser = db.AspNetUsers.SingleOrDefault(u => u.MyMobilePhone == context.UserName.Substring(1));
                if (aspnetuser == null)
                {
                    context.SetError("invalid_grant", "手机号码或密码不正确。");
                }else
                {
                    try
                    {
                        user = await userManager.FindAsync(aspnetuser.UserName, context.Password);
                    }catch(Exception ex)
                    {

                    }


                 
                }

              
                if (user == null)
                {
                    context.SetError("invalid_grant", "手机号码或密码不正确。");
                }
            }
            else
            {
                // user = await userManager.FindAsync(context.UserName, context.Password);
                user = null;
            }

            if (user == null)
            {
                context.SetError("invalid_grant", "用户名或密码不正确。");
                return;
            }

            try
            {
                ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
            OAuthDefaults.AuthenticationType);
                ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                    CookieAuthenticationDefaults.AuthenticationType);

                AuthenticationProperties properties = CreateProperties(user.UserName);
                AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
                context.Validated(ticket);
                context.Request.Context.Authentication.SignIn(cookiesIdentity);
            }catch(Exception ex)
            {

            }

         
        }