/// <summary> /// 用户登录 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static Dm_ResultDefault Login(User_Login obj) { try { using (IDbConnection conn = new MySqlConnection(DapperHelper.CONNECTIONSTRING)) { //session取用户id UserBaseInfo ubi = HttpSession.GetSession("UserBaseInfo"); conn.Open(); IDbTransaction tran = conn.BeginTransaction(); try { User_Info_Entity user_info = new User_Info_Entity(); var dynamicParams = new DynamicParameters(); List <User_Info_Entity> num = new List <User_Info_Entity>(); int name = 0; dynamicParams.Add("login_password", obj.Login_PassWord); if (Regex.IsMatch(obj.Login_Name, @"^1[3456789]\d{9}$")) { user_info.user_mobile = obj.Login_Name; dynamicParams.Add("user_mobile", obj.Login_Name); name = conn.RecordCount <User_Info_Entity>("where user_mobile=@user_mobile and user_state=1 ", dynamicParams); if (name == 0) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "账号错误!" }); } num = conn.GetList <User_Info_Entity>("where user_mobile=@user_mobile and login_password=@login_password and user_state=1 ", dynamicParams).ToList(); if (num == null) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "密码错误!" }); } } else { user_info.user_nickname = obj.Login_Name; dynamicParams.Add("user_nickname", obj.Login_Name); name = conn.RecordCount <User_Info_Entity>("where user_nickname=@user_nickname and user_state=1 ", dynamicParams); if (name == 0) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "账号错误!" }); } num = conn.GetList <User_Info_Entity>("where user_nickname=@user_nickname and login_password=@login_password and user_state=1 ", dynamicParams).ToList(); if (num == null) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "密码错误!" }); } } Check_Token_Entity cte = new Check_Token_Entity(); cte.cktoken_id = Guid.NewGuid(); cte.cktoken_ip = obj.Login_Ip; cte.cktoken_ur_id = num[0].user_id; cte.cktoken_time = DateTime.Now; cte.cktoken_token = Guid.NewGuid().ToString(); cte.cktoken_state = 1; User_LoginDAO.TokenAdd(conn, tran, cte); if (num[0].login_firsttime == new DateTime()) { User_Info_Entity uie = new User_Info_Entity(); uie.user_id = num[0].user_id; uie.login_firsttime = DateTime.Now; uie.login_ip = obj.Login_Ip; uie.up_user = ubi.UserId; uie.up_date = DateTime.Now; if (User_LoginDAO.uieUpdate(conn, tran, uie) == 0) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "修改信息失败" }); } } else { User_Info_Entity uie = new User_Info_Entity(); uie.user_id = num[0].user_id; uie.login_lasttime = DateTime.Now; uie.login_ip = obj.Login_Ip; uie.up_user = ubi.UserId; uie.up_date = DateTime.Now; if (User_LoginDAO.uieUpdates(conn, tran, uie) == 0) { return(new Dm_ResultDefault() { Result = 0, ResultDesc = "修改信息失败" }); } } // Dm_ResultDefault a=Token(); tran.Commit(); Task <Dm_ResultDefault> a = Token(obj); return(new Dm_ResultDefault() { Result = 1, ResultDesc = "" }); } catch (Exception ex) { tran.Rollback(); throw ex; } } } catch (Exception e) { throw e; } }
/// <summary> /// token 新增 /// </summary> /// <param name="conn"></param> /// <param name="tran"></param> /// <param name="entity"></param> /// <returns></returns> public static Guid?TokenAdd(IDbConnection conn, IDbTransaction tran, Check_Token_Entity entity) { return(conn.Insert <Guid, Check_Token_Entity>(entity, tran)); }