Exemplo n.º 1
0
        /// <summary>
        /// 找回密码(重置密码)
        /// </summary>
        /// <param name="LoginName"></param>
        /// <param name="psw"></param>
        /// <returns></returns>
        public StateCode ResetPwd(string mobile, string psw)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();
                    var user = s.Get <User>("where mobile = @0", mobile);
                    if (user == null)
                    {
                        s.RollBack(); return(StateCode.State_207);
                    }
                    if (user.state == 0)
                    {
                        s.RollBack(); return(StateCode.State_209);
                    }
                    s.ExecuteScalar("update tb_user set psw = @0 where mobile = @1", psw, mobile);

                    var log = new APILogs();
                    log.created_date = DateTime.Now;
                    log.content      = string.Format("用户{0}重置密码成功!", mobile);
                    s.Insert <APILogs>(log);
                    s.Commit();
                }
                catch
                {
                    s.RollBack();
                    return(StateCode.State_500);
                }
                return(StateCode.State_200);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 更新令牌最后活动时间
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public StateCode TokenUpdate(string token)
 {
     using (ISession s = SessionFactory.Instance.CreateSession())
     {
         try
         {
             var ret = s.ExecuteScalar(string.Format("exec p_user_token_update '{0}'", token));
             return(StateCode.State_200);
         }
         catch (Exception ex)
         {
             APILogs log = new APILogs();
             log.content      = "更新令牌最后活动时间异常==》" + ex.ToString();
             log.created_date = DateTime.Now;
             log.type         = 1;
             s.Insert(log);
             return(StateCode.State_500);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 微信端注册
        /// </summary>
        /// <param name="weChatUser"></param>
        /// <param name="mobile"></param>
        /// <param name="psw"></param>
        /// <param name="rpsw"></param>
        /// <param name="vcode"></param>
        /// <returns></returns>
        public StateCode WeChatRegister(WeChatUser weChatUser, string mobile, string psw, string rpsw, string vcode)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();

                    //短信验证码不存在
                    SmsMessage sms = s.Get <SmsMessage>("where mobile = @0  and type = @1", mobile, 1);
                    if (sms == null)
                    {
                        return(StateCode.State_54);
                    }

                    //验证码错误
                    if (!vcode.Equals(sms.content))
                    {
                        return(StateCode.State_53);
                    }

                    //计算时间间隔
                    TimeSpan t = DateTime.Now - sms.created_time;
                    if (t.TotalSeconds > 300)
                    {
                        return(StateCode.State_52);
                    }

                    //是否已经被注册
                    int exist_l = s.Exist <User>("where login_name = @0", mobile);
                    if (exist_l > 0)
                    {
                        return(StateCode.State_202);
                    }

                    //是否已经被注册
                    int exist_m = s.Exist <User>("where mobile = @0", mobile);
                    if (exist_m > 0)
                    {
                        return(StateCode.State_202);
                    }

                    //两次密码不一致
                    if (!rpsw.Equals(psw))
                    {
                        return(StateCode.State_203);
                    }

                    User user = new User();
                    user.mobile       = mobile;
                    user.psw          = StringHelper.ConvertTo32BitSHA1(psw);
                    user.created_date = DateTime.Now;
                    s.Insert(user);

                    //设置用户ID
                    weChatUser.user_id = user.id;

                    //用户详情
                    UserDetail detail = new UserDetail();
                    detail.user_id = user.id;
                    s.Insert(detail);



                    //设置密码
                    s.ExcuteUpdate("update tb_user set login_name = @0,mobile = @0,psw = @1 where id = @2  ", user.mobile, user.psw, user.id);

                    //如果在微信端打开,则绑定微信
                    if (weChatUser != null)
                    {
                        //修改用户状态
                        s.ExcuteUpdate("update tb_user set is_bind_wechat = @0  where id = @1 ", true, user.id);
                        s.ExcuteUpdate("update tb_wx_user set user_id = @0 where openid = @1", user.id, weChatUser.openid);
                    }

                    s.Commit();
                    return(StateCode.State_200);
                }
                catch (Exception ex)
                {
                    s.RollBack();
                    APILogs log = new APILogs();
                    log.content      = "[WeChatRegister]注册异常==》" + ex.ToString();
                    log.created_date = DateTime.Now;
                    s.Insert(log);
                    return(StateCode.State_500);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rpsw"></param>
        /// <param name="vcode"></param>
        /// <returns></returns>
        public StateCode Register(User user, string rpsw, string vcode, SignPackage signPackage)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();

                    //短信验证码不存在
                    SmsMessage sms = s.Get <SmsMessage>("where mobile = @0  and type = @1", user.mobile, 1);
                    if (sms == null)
                    {
                        return(StateCode.State_54);
                    }

                    //验证码错误
                    if (!vcode.Equals(sms.content))
                    {
                        return(StateCode.State_53);
                    }

                    //计算时间间隔
                    TimeSpan t = DateTime.Now - sms.created_time;
                    if (t.TotalSeconds > 300)
                    {
                        return(StateCode.State_52);
                    }

                    //是否已经被注册
                    int exist_m = s.Exist <User>("where mobile = @0", user.mobile);
                    if (exist_m > 0)
                    {
                        return(StateCode.State_202);
                    }

                    //两次密码不一致
                    if (!rpsw.Equals(user.psw))
                    {
                        return(StateCode.State_203);
                    }

                    user.state        = 1;
                    user.login_name   = user.mobile;
                    user.created_date = DateTime.Now;
                    user.psw          = StringHelper.ConvertTo32BitSHA1(user.psw);
                    s.Insert(user);

                    //用户详情
                    UserDetail detail = new UserDetail();
                    detail.user_id = user.id;
                    s.Insert(detail);

                    if (signPackage != null)
                    {
                        //重置当前用户所有令牌状态
                        s.ExcuteUpdate("update tb_user_token set is_enable = @0 where user_id = @1", false, user.id);
                        signPackage.Token = Guid.NewGuid().ToString("N");
                        UserToken token = new UserToken();
                        token.created_date = DateTime.Now;
                        token.os           = signPackage.OS;
                        token.last_time    = DateTime.Now;
                        token.user_id      = user.id;
                        token.imei         = signPackage.IMEI;
                        token.imsi         = signPackage.IMSI;
                        token.token        = signPackage.Token;
                        token.is_enable    = true;
                        s.Insert(token);
                    }

                    s.Commit();
                    return(StateCode.State_200);
                }
                catch (Exception ex)
                {
                    s.RollBack();

                    APILogs log = new APILogs();
                    log.content      = "[Register]注册异常==》" + ex.ToString();
                    log.created_date = DateTime.Now;
                    s.Insert(log);

                    return(StateCode.State_500);
                }
            }
        }