Exemple #1
0
        /// <summary>
        /// 用户登录,http://mobile.huobi3j.com/user/login
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码(不加密)</param>
        /// <returns></returns>
        public ActionResult Login(string username,string password)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                return GetJson(new JsonResponse { status = false, message = "参数有误!" });
            }

            string pwdMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
            DAL.Users dal = new DAL.Users();
            Model.Users user = null;
            if (Regex.IsMatch(username, @"^\d+$"))//通讯号码
            {
                user = dal.GetEntity(new string[] { "CheckState", "UIN", "LoginPwd" }, 1, username, pwdMd5);
            }
            else if (Regex.IsMatch(username, Validator.EmailPattern))
            {
                user = dal.GetEntity(new string[] { "CheckState", "Email", "LoginPwd" }, 1, username, pwdMd5);
            }
            else if (Regex.IsMatch(username, @"\w+") /*&& Regex.IsMatch(loginKey, @"\d+")*/ )//自定义登陆帐号
            {
                user = dal.GetEntity(new string[] { "CheckState", "LoginName", "LoginPwd" }, 1, username, pwdMd5);
            }
            else
            {
                return null;
            }

            if (user == null)
            {
                return GetJson(new JsonResponse { status = false, message = "用户不存在!" });
            }

            return GetJson(new { status = true, data = user });
        }