示例#1
0
        public async Task <JsonResult> Login([FromBody] UserModel logModel)
        {
            if (string.IsNullOrEmpty(logModel.UserName) || string.IsNullOrEmpty(logModel.PassWord))
            {
                return(Error("用户名或密码不能为空!"));
            }

            if (string.IsNullOrEmpty(logModel.VerfyCode))
            {
                return(Error("图形验证码不能为空!"));
            }

            if (!string.Equals(logModel.VerfyCode, EncyryptionUtil.DESDecrypt(logModel.CodeDes), StringComparison.InvariantCultureIgnoreCase))
            {
                return(Error("图形验证码错误!"));
            }
            var pwd  = EncyryptionUtil.AESEncrypt(logModel.PassWord);
            var user = await _accountService.GetBy(logModel.UserName, pwd);

            if (user != null)
            {
                var userModel = _mapper.Map <UserModel>(user);
                userModel.LoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                userModel.LoginIP   = HttpContext.Connection.RemoteIpAddress.ToString();
                userModel.Amount    = user.Money.Value;

                //记录登陆IP
                await _accountService.AddLoginIp(user.UserId, userModel.LoginIP);

                var token = _authenticationSupport.SignIn(userModel);
                return(SucessResult(token));
            }

            return(Error("用户名或密码错误!"));
        }
        public async Task <List <Dictionary <string, string> > > FileUpload()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            List <Dictionary <string, string> > list = new List <Dictionary <string, string> >();
            string pata = "/File/Whole/" + DateTime.Now.ToString("yyyyMMdd");

            LogHelper.WriteLog("pata : " + pata, "UTIController.FileUpload");
            string root = HttpContext.Current.Server.MapPath("/" + pata);//指定要将文件存入的服务器物理位置

            LogHelper.WriteLog("root: " + root, "UTIController.FileUpload");
            if (!Directory.Exists(root))//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(root);
            }
            var provider = new MultipartFormDataMemoryStreamProvider();

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                LogHelper.WriteLog("Read the form data", "UTIController.FileUpload");
                // This illustrates how to get the file names.
                foreach (var fileContent in provider.FileContents)
                {
                    LogHelper.WriteLog("This illustrates how to get the file names.", "UTIController.FileUpload");
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    string fileName = fileContent.Headers.ContentDisposition.FileName.Replace("\"", "");
                    dic.Add("OldFileName", fileName);
                    string Ext = Path.GetExtension(fileName);
                    dic.Add("ExtName", Ext);
                    fileName = EncyryptionUtil.GetMd5Utf8(EncyryptionUtil.AESEncrypt(Guid.NewGuid().ToString())) + Ext;
                    dic.Add("NewFileName", fileName);
                    dic.Add("FilePath", FlieServiceUrl + pata + "/" + fileName);
                    var stream = await fileContent.ReadAsStreamAsync();

                    using (StreamWriter sw = new StreamWriter(Path.Combine(root, fileName)))
                    {
                        stream.CopyTo(sw.BaseStream);
                        sw.Flush();
                        list.Add(dic);
                    }
                }
                //TODO:这样做直接就将文件存到了指定目录下,暂时不知道如何实现只接收文件数据流但并不保存至服务器的目录下,由开发自行指定如何存储,比如通过服务存到图片服务器
                //foreach (var key in provider.FormData.AllKeys)
                //{//接收FormData
                //    dic.Add(key, provider.FormData[key]);
                //}
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(e.Message);
                throw;
            }
            return(list);
        }
示例#3
0
        public t1_user CreateEntity(string userName, string password)
        {
            var user = new t1_user();

            user.UserName       = userName;
            user.Mobile         = userName;
            user.Mobile_Valid   = "Y";
            user.EncryptionType = "AES";
            user.PassWord       = EncyryptionUtil.AESEncrypt(password);
            user.CreatedTime    = DateTime.Now;
            user.Money          = 0;
            return(user);
        }
示例#4
0
        /// <summary>
        /// 重设密码,如果没有就注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task ResetPassword(string userName, string password)
        {
            var user = await _context.t1_users.FirstOrDefaultAsync(e => e.UserName == userName);

            if (user == null)
            {
                user = CreateEntity(userName, password);
                _context.t1_users.Add(user);
            }
            else
            {
                user.PassWord = EncyryptionUtil.AESEncrypt(password);
            }
            await _context.SaveChangesAsync();
        }