public object login(LoginInput input) { var user = (from u in this.db.users where u.username == input.username select u).FirstOrDefault(); if (user != null) { if (user.password == input.password) { var token = new JwtBuilder() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSecret(Config.secret) .AddClaim("user", user) .Build(); user.token = token; return(CommonRtn.Success("user", user)); } else { return(CommonRtn.Error("密码错误")); } } else { return(CommonRtn.Error("用户不存在")); } }
public object insert([FromRoute] string dvoFullName, [FromForm] DevExtremInput input) { var type = Assembly.GetEntryAssembly().GetType(dvoFullName); var viewAttr = (ViewAttribute)type.GetCustomAttribute(typeof(ViewAttribute)); var dbSet = (from m in this.db.GetType().GetMembers() where m.Name == viewAttr.entity select m).FirstOrDefault(); if (dbSet != null) { // viewAttr.entity // var dbSetMethodInfo = typeof (DbContext).GetMethod ("Set"); // dynamic dbSet = dbSetMethodInfo.MakeGenericMethod (type).Invoke (this.db, null); dynamic instance = Activator.CreateInstance(type); JsonConvert.PopulateObject(input.values, instance); //Validate(order); // if (!ModelState.IsValid) // return false; // this.hk.orgManage.Add (user); // dbSet.Add (instance); // db.SaveChanges (); return(null); // return instance; } else { return(CommonRtn.Error("找不到DVO")); } }
public CommonRtn signup([FromForm] SignupInput input) { var exisitUser = (from user in this.sysContext.users where user.phone == input.phone select user).Count(); var message = (from msg in this.sysContext.messages where msg.phone == input.phone orderby msg.createTime descending select msg).First(); if (message == null) { return(CommonRtn.Error("请先发送短信验证码")); } if (message.code != input.authcode) { return(CommonRtn.Error("短信验证码错误")); } if (exisitUser > 0) { return(new CommonRtn { success = false, message = "用户已经注册" }); } else { var user = new User { phone = input.phone, loginPassword = DESEncrypt.Encrypt(input.loginPassword), id = Guid.NewGuid().ToString() }; this.sysContext.users.Add(user); this.sysContext.SaveChanges(); return(new CommonRtn { success = true, message = "注册成功" }); } }
public CommonRtn forgotPassword([FromForm] AppForgotPasswordInput input) { var userExist = (from user in this.sysContext.users where user.phone == input.phone select user).First(); if (userExist != null) { var msg = (from message in this.sysContext.messages where message.phone == input.phone orderby message.createTime select message).First(); if (msg != null) { if (msg.code == input.authcode) { userExist.loginPassword = DESEncrypt.Encrypt(input.newPassword); var token = userService.getUserToken(new AppTokenOutput { user = userExist }); return(CommonRtn.Success(new Dictionary <string, object> { { "token", token } })); } else { return(CommonRtn.Error("短信验证码错误")); } } else { return(CommonRtn.Error("请先发送短信验证码")); } } else { return(CommonRtn.Error("手机号尚未注册为用户")); } }
public object send(int orderId) { var order = this.db.orders.Find(orderId); if (order != null) { order.status = OrderStatus.Send; this.db.SaveChanges(); return(CommonRtn.Success(null, "成功")); } else { return(CommonRtn.Error("未知的订单")); } }
public object payOrder(int orderId) { var order = this.db.orders.Find(orderId); if (order != null) { order.status = OrderStatus.Pay; this.db.SaveChanges(); return(CommonRtn.Success(null, "购买成功")); } else { return(CommonRtn.Error("购买失败")); } }
public CommonRtn signup([FromBody] LoginInput input) { var user = (from u in this.db.users where u.username == input.username select u).FirstOrDefault(); if (user != null) { return(CommonRtn.Error("用户已经注册")); } else { var newUser = new User { nickname = "新用户", username = input.username, password = input.password, roleType = RoleType.User }; this.db.users.Add(newUser); this.db.SaveChanges(); return(CommonRtn.Success(new Dictionary <string, object> { { "user", newUser } })); } }
public CommonRtn appLogin([FromForm] AppUserLoginInput loginInput) { var exisitUser = (from user in this.sysContext.users where user.phone == loginInput.phone select user).FirstOrDefault(); if (exisitUser != null) { // if (DESEncrypt.DecryptString(exisitUser.loginPassword) == loginInput.loginPassword) // { var loginIp = this.commonService.getRequestIp(); exisitUser.loginNumber++; exisitUser.loginIP = loginIp; exisitUser.mechineId = loginInput.mechineId; var token = this.userService.getUserToken( new AppTokenOutput { user = new User { id = exisitUser.id, phone = exisitUser.phone, companyId = exisitUser.companyId, companyFrameworkId = exisitUser.companyFrameworkId } }); exisitUser.token = token; Console.WriteLine("companyFrameowrkId:" + this.userService.decodeToken(token).user.companyFrameworkId); Console.WriteLine("cpmid" + exisitUser.companyFrameworkId); Console.WriteLine("companyId" + exisitUser.companyId); this.sysContext.SaveChanges(); return(CommonRtn.Success(new Dictionary <string, object>() { { "token", token }, { "user", exisitUser } }, "登录成功")); } else { return(CommonRtn.Error("登录失败,用户不存在")); } }
public object appLogin([FromBody] AppUserLoginInput loginInput) { var exisitUser = (from user in this.sysContext.users where user.phone == loginInput.phone select user).FirstOrDefault(); if (exisitUser != null) { if (DESEncrypt.DecryptString(exisitUser.loginPassword) == loginInput.loginPassword) { var loginIp = this.commonService.getRequestIp(); exisitUser.loginNumber++; exisitUser.loginIP = loginIp; exisitUser.mechineId = loginInput.mechineId; var token = this.userService.getUserToken(new AppTokenOutput { user = exisitUser }); exisitUser.token = token; this.sysContext.SaveChanges(); return(new CommonRtn { success = true, message = "登录成功", resData = new Dictionary <string, object>() { { "token", token } } }); } else { return(CommonRtn.Error("登录失败,用户密码错误")); } } else { return(new CommonRtn { success = false, message = "登录失败,用户不存在", }); } }
public CommonRtn resetPassword([FromForm] ResetPasswordInput input) { var tokenUser = this.userService.getUserFromAuthcationHeader(); var user = this.sysContext.users.Find(tokenUser.id); if (user != null) { if (DESEncrypt.DecryptString(user.loginPassword) == input.oldPassword) { user.loginPassword = DESEncrypt.Encrypt(input.newPassword); this.sysContext.SaveChanges(); return(CommonRtn.Success(new Dictionary <string, object> { }, "修改密码成功")); } else { return(CommonRtn.Error("旧密码错误")); } } else { return(CommonRtn.Error("用户尚未登录")); } }