public IHttpActionResult Create([FromBody] AddActivity activity) { AmigoWallEntities db = new AmigoWallEntities(); var user = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name); C_Activity ac = new C_Activity { id = Guid.NewGuid().ToString(), ActivityPost = activity.ActivityPost, ActivityName = activity.ActivityName, ActivityStart = activity.ActivityStart, ActivityEnd = activity.ActivityEnd, Location = activity.Location, LocationProxy = activity.LocationProxy == "" ? null : activity.LocationProxy, Album = activity.Album == "" ? null : activity.Album, pv = 0, IsDelete = false, IsPublish = false, pvpy = 0, Creator = user.Id, AddTime = UtilityHelper.getNow() }; db.C_Activity.Add(ac); db.SaveChanges(); return Json(new { Code = 10000, Detail = 1 }); }
public IHttpActionResult MyActivityList() { AmigoWallEntities db = new AmigoWallEntities(); var list = db.C_Activity.Where(u => u.AspNetUsers.UserName == User.Identity.Name).Select(u => new { ActivityName = u.ActivityName, ActivityPost = u.ActivityPost, ActivityId = u.id }); return Json(new { Code = 10000, Detail = list }); }
public static bool VerifyMobileCode(string mobile, int code) { if (testAccount.Contains(mobile)) { return true; } AmigoWallEntities db = new AmigoWallEntities(); DateTime dt = UtilityHelper.getNow().AddMinutes(-5); //延迟5分钟 if (db.cm_SMS.Any(u => (u.mobile == mobile && u.code == code && u.CreateDate > dt))) { var obj = db.cm_SMS.Where(u => u.mobile == mobile).ToList(); db.cm_SMS.RemoveRange(obj); return true; } else { return false; } }
public IHttpActionResult AddNewAlbum([FromBody] AddNewAlbumModel model) { AmigoWallEntities db = new AmigoWallEntities(); var album = new tb_Album { AddDate = UtilityHelper.getNow(), AlbumIcon = model.ImageUrl, AlbumName = model.AlbumName, Organizer = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name).Id, UserId = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name).Id, id = Guid.NewGuid().ToString() }; db.tb_Album.Add(album); db.SaveChanges(); return Json(new { Code = 10000, Detail = new { } }); }
public IHttpActionResult GetMyConfig() { AmigoWallEntities db = new AmigoWallEntities(); var user = db.AspNetUsers.Include("AspNetUsers_Org").Include("AspNetUsers_Person").Single(u => u.UserName == User.Identity.Name); return Json(new { Code = 10000, Detail = new { IsOrganizer = user.IsOrganization, Portrait = user.Portrait, NickName = user.NickName, } }); }
public static void Log(int type,string message,string source) { var log = new cm_Log { AddDate = getNow(), id = Guid.NewGuid().ToString(), Message = message, Source = source, Type = type }; AmigoWallEntities db = new AmigoWallEntities(); db.cm_Log.Add(log); db.SaveChanges(); }
public IHttpActionResult AddNewLocation([FromBody] AddNewLocationModel model) { AmigoWallEntities db = new AmigoWallEntities(); var location = new tb_Location { Id = Guid.NewGuid().ToString(), AddTime = UtilityHelper.getNow(), Latitude = model.latitude, longitude = model.longtitude, LocationName = model.LocationName, FullAddress = model.AddressName, Status = 0, UserId = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name).Id }; db.tb_Location.Add(location); db.SaveChanges(); return Json(new { Code = 10000, Detail = new { } }); }
public IHttpActionResult ModifyLocation([FromBody] ModeifyLocation model) { AmigoWallEntities db = new AmigoWallEntities(); var obj = db.tb_Location.Single(u => u.Id == model.LocationId); obj.LocationName = model.LocationName; obj.FullAddress = model.AddressName; obj.Latitude = model.latitude; obj.longitude = model.longtitude; db.SaveChanges(); return Json(new { Code = 10000, Detail = new { // data = list } }); }
public IHttpActionResult saveAlbumById([FromBody] AlbumModel model) { AmigoWallEntities db = new AmigoWallEntities(); var Org = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name); var OrgId = Org.Id; var album = db.tb_Album.Single(u => u.id == model.AlbumId); album.AlbumName = model.AlbumName; db.SaveChanges(); var list = db.tb_Album.Where(u => !u.IsDelete && u.Organizer == OrgId).Select(u => new { AlbumId = u.id, AlbumName = u.AlbumName, AlbumIcon = u.AlbumIcon }); return Json(new { Code = 10000, Detail = new { data = list } }); }
public string MobielWebLogin() { string id = Guid.NewGuid().ToString(); cm_ConfirmMobileLogin login = new cm_ConfirmMobileLogin { id = id, AddDate = UtilityHelper.getNow(), IsConfirmed = false, UserName = User.Identity.Name, }; HuoDongYou.Models.Entities.AmigoWallEntities db = new HuoDongYou.Models.Entities.AmigoWallEntities(); db.cm_ConfirmMobileLogin.Add(login); db.SaveChanges(); return id; }
public IHttpActionResult getProfile() { AmigoWallEntities db = new AmigoWallEntities(); var obj = db.AspNetUsers.Include("AspNetUsers_Person").Include("AspNetUsers_Org").Single(u => u.UserName == User.Identity.Name); if (obj.IsOrganization) { return Json(new { Code = 10000, Detail = new { ItemID = 1, Name = obj.NickName, Portrait = obj.Portrait, Mobilephone = obj.AspNetUsers_Org.PhoneNo, Gender = 2 } }); } else { return Json(new { Code = 10000, Detail = new { } }); } }
public IHttpActionResult getMyAlbumList() { AmigoWallEntities db = new AmigoWallEntities(); var Org = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name); var OrgId = Org.Id; var list = db.tb_Album.Where(u => !u.IsDelete && u.Organizer == OrgId).Select(u => new { AlbumId = u.id, AlbumName = u.AlbumName, AlbumIcon = u.AlbumIcon }); return Json(new { Code = 10000, Detail = list }); }
public IHttpActionResult sat(int number) { AmigoWallEntities db = new AmigoWallEntities(); cm_Sat sat = new cm_Sat { id = Guid.NewGuid().ToString(), Adddate = DateTime.Now, number = number, UserName = User.Identity.Name }; db.cm_Sat.Add(sat); db.SaveChanges(); return Json(new { r = true }); }
public IHttpActionResult changeUserPortrait([FromBody] changeUserPortrait model) { AmigoWallEntities db = new AmigoWallEntities(); var obj = db.AspNetUsers.Include("AspNetUsers_Person").Include("AspNetUsers_Org").Single(u => u.UserName == User.Identity.Name); obj.Portrait = model.imageurl; db.SaveChanges(); return Json(new { Code = 10000, Detail = new { } }); }
public async Task<IHttpActionResult> OrgRegister([FromBody] registerObj model) { AmigoWallEntities db = new AmigoWallEntities(); if (!HDYHelper.VerifyMobileCode(model.Mobile, model.Code)) { return Json(new { Code = 1, Message = "验证码错误或已经失效" }); } //可以注册,是自己的号码 if (db.AspNetUsers_Org.Any(u => u.PhoneNo == model.Mobile)) { return Json(new { Code = 1, Message = "该手机号码已经被注册" }); } //开始创建新账户 //注册id string id = Guid.NewGuid().ToString(); var user = new ApplicationUser() { Id = id, UserName = "******" + Guid.NewGuid().ToString(), NickName = "o" + model.Mobile, IsOrganization = true, RegisterTime = UtilityHelper.getNow(), IsActive = true, EmailConfirmed = false, // Email = para.Email, PhoneNumberConfirmed = false, AccessFailedCount = 0, LockoutEnabled = true, Sex = 2, //表示没有性别认定 Portrait = "http://hdy.awblob.com/portrait/orgdefault.jpg", LoginPassword = model.Password }; IdentityResult result = await Request.GetOwinContext().GetUserManager<ApplicationUserManager>().CreateAsync(user); if (!result.Succeeded) { return Json(new { Code = 1, Message = "注册不成功" }); } else { //注册成功 HuoDongYou.Models.Entities.AspNetUsers_Org org = new Models.Entities.AspNetUsers_Org { id = id, PhoneNo = model.Mobile }; C_Follow follow = new C_Follow { FromId = id, ToId = id, AddDate = UtilityHelper.getNow() }; //C_Follow follow2 = new C_Follow //{ // FromId = id, // ToId = "34d6c28a-6c9d-474c-90a9-4ba66a52f010" //}; db.C_Follow.Add(follow); // db.C_Follow.Add(follow2); db.AspNetUsers_Org.Add(org); db.SaveChanges(); } string grant_type = "password"; string password = BlobString.PasswordString; ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "grant_type=" + grant_type; postData += ("&password="******"o" + model.Password); postData += "&username="******"http://newhuodongyou.chinacloudsites.cn/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 = (HttpWebResponse)myRequest.GetResponse(); 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_Org.Include("AspNetUsers").Single(u => u.AspNetUsers.UserName == username); return Json(new { Code = 10000, Detail = new { token = json["access_token"].ToString(), IsValid = true, expired = json[".expires"].ToString(), NickName = myuser.AspNetUsers.NickName, UserName = myuser.AspNetUsers.UserName, Portrait = myuser.AspNetUsers.Portrait } }); }
public async Task<IHttpActionResult> Reset([FromBody] registerObj model) { AmigoWallEntities db = new AmigoWallEntities(); if (HDYHelper.VerifyMobileCode(model.Mobile, model.Code)) { return Json(new { Code = 1, Detail = "验证码错误或者已经失效" }); } else { //可以注册,是自己的号码 if (db.AspNetUsers_Org.Any(u => u.PhoneNo == model.Mobile)) { var obj = db.AspNetUsers_Org.Include("AspNetUsers").Single(u => u.PhoneNo == model.Mobile); obj.AspNetUsers.LoginPassword = model.Password; db.SaveChanges(); return Json(new { Code = 10000, detail = 1 }); } else { return Json(new { Code = 10000, Detail = 2 }); } } }
public IHttpActionResult SMSVerify([FromBody] SMSVerify model) { AmigoWallEntities db = new AmigoWallEntities(); DateTime dt = UtilityHelper.getNow().AddMinutes(-2); if (HDYHelper.VerifyMobileCode(model.mp, model.vcode)) { return Json(new { Code = 10000, Detail = 1 }); } else { return Json(new { Code = 100, Message = "验证码错误或已经失效" }); } }
public IHttpActionResult refreshToken() { AmigoWallEntities db = new AmigoWallEntities(); string mobile = db.AspNetUsers_Person.Include("AspNetUsers").Single(u => u.AspNetUsers.UserName == User.Identity.Name).PhoneNo; string grant_type = "password"; // string password = string.Empty; // password = HttpContext.Current.Application["access_token_token"].ToString(); string password = BlobString.PasswordString; ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "grant_type=" + grant_type; postData += ("&password="******"&username="******"http://172.29.52.15:47897/token"); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://pengyouqiang.com/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 = (HttpWebResponse)myRequest.GetResponse(); 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); bool isComplete = db.AspNetUsers_Person.Include("AspNetUsers").First(u => u.PhoneNo == mobile).AspNetUsers.Sex < 2; return Json(new verifycode { r = 1, token = json["access_token"].ToString(), isComplete = isComplete, expired = json[".expires"].ToString() }); }
public IHttpActionResult getPlaceList() { AmigoWallEntities db = new AmigoWallEntities(); var Org = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name); var OrgId = Org.Id; var list = db.tb_Location.Where(u => u.UserId == OrgId).Select(u => new { Id = u.Id, LocationName = u.LocationName, LocationAddress = u.FullAddress, Latitude = u.Latitude, Longitude = u.longitude, Description = u.Description }); return Json(new { Code = 10000, Detail = new { data = list }, }); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { //if(context.Password.IndexOf(BlobString.PasswordString)!=0) //{ // context.SetError("invalid_grant", "The user name or password is incorrect~~."); // return; //} // string ContextPassword = context.Password.Substring(BlobString.PasswordString.Length); AmigoWallEntities db = new AmigoWallEntities(); Regex dReg = new Regex("[0-9]{11,11}"); string userId=string.Empty; if(context.Password.First()=='o') { if (dReg.IsMatch(context.UserName)) { //如果是手机注册 var userModel = db.AspNetUsers_Org.Include("AspNetUsers").SingleOrDefault(u => u.PhoneNo == context.UserName && u.AspNetUsers.LoginPassword==context.Password.Substring(1)); if (userModel != null) userId = userModel.id; } else { //如果不是手机注册 // var userModel = // db.AspNetUsers.SingleOrDefault(u => u.Email == context.UserName && u.LoginPassword == ContextPassword); AspNetUsers userModel = null; if (userModel != null) userId = userModel.Id; } }else { if (dReg.IsMatch(context.UserName)) { //如果是手机注册 var userModel = db.AspNetUsers_Org.Include("AspNetUsers").SingleOrDefault(u => u.PhoneNo == context.UserName); if (userModel != null) userId = userModel.id; } else { //如果不是手机注册 AspNetUsers userModel = null; if (userModel != null) userId = userModel.Id; } } var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>(); ApplicationUser user = await userManager.FindByIdAsync(userId); // user = await userManager.FindAsync(userName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } 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); }