Пример #1
0
        /// <summary>
        /// 生成二维码 json格式
        /// </summary>
        private void GenerateJson()
        {
            string value = "";
            int    count = JsonList.Count;

            for (int i = 0; i < count; i++)
            {
                if (string.IsNullOrWhiteSpace(JsonList[i].Key) || !JsonList[i].Checked)
                {
                    continue;
                }
                value += "\"" + JsonList[i].Key + "\":\"" + JsonList[i].Value + "\"";
                value += count - i == 1 ? "" : ",";
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                CrossToastPopUp.Current.ShowToastWarning("空字符串,请检查", ToastLength.Long);
                return;
            }
            else
            {
                value = "{" + value + "}";
            }

            string base64 = Base64Helper.Base64Encode(Encoding.UTF8, value);

            JsonBarCode = base64;
        }
Пример #2
0
        public void AddNewTest()
        {
            using (System.Data.Entity.Core.EntityClient.EntityConnection entity = new System.Data.Entity.Core.EntityClient.EntityConnection("MyProjectEF1"))
            {
                entity.Open();
                EntityCommand cmd = entity.CreateCommand();
                cmd.CommandText = @"select doubt d from uLibrary as d where d.";
            }



            MyProjectEF mp = new MyProjectEF();



            mp.uLibrary.ToList();

            mp.uUsers.Add(new uUser()
            {
                UserName     = "******",
                Password     = Base64Helper.Base64Encode("msc@123321"),
                Email        = "*****@*****.**",
                CreationDate = DateTime.Now,
                EditDate     = DateTime.Now,
                FirstName    = "Edwin",
                LastName     = "Nie",
                FullName     = "Edwin Nie",
                LCV          = false
            });
            mp.SaveChanges();
        }
Пример #3
0
        public async Task <IEnumerable <T> > GetAsync <T>(string link)
        {
            IEnumerable <T> result = null;

            using (var httpClient = new HttpClient())
            {
                string jsonResult = string.Empty;

                httpClient.BaseAddress = new Uri(Constants.baseLink);
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Add(Constants.customHeaderKey, Base64Helper.Base64Encode(Constants.customHeaderValue));

                HttpResponseMessage response = await httpClient.GetAsync(link);

                response.EnsureSuccessStatusCode();

                if (response.IsSuccessStatusCode)
                {
                    jsonResult = await response.Content.ReadAsStringAsync();

                    result = JsonConvert.DeserializeObject <IEnumerable <T> >(jsonResult);
                }
            }


            return(result);
        }
Пример #4
0
        public AccountLoginResultDTO Login(AccountLoginDTO dto)
        {
            AccountLoginResultDTO result = new AccountLoginResultDTO();

            var    loginUser = _userService.Single(m => m.LoginName == dto.UserName);
            string password  = EncryptHelper.Encrypt(dto.Password);

            if (loginUser != null && loginUser.LoginPWD == password)
            {
                result.IsSuccess = true;
            }
            else
            {
                result.IsSuccess = false;
                result.Message   = "用户名或密码错误";
                return(result);
            }


            string cookieValueToEncrypt = string.Format("{0}_{1}_{2}", loginUser.UserID, loginUser.LoginName, DateTime.Now);
            string encryptCookieValue   = EncryptHelper.Encrypt(cookieValueToEncrypt);
            string cacheKey             = string.Format("AccountService_Login_{0}", loginUser.UserID);

            _cache.Remove(cacheKey);
            _cache.Set(cacheKey, encryptCookieValue, TimeSpan.FromHours(1));

            result.CookieValue         = encryptCookieValue;
            result.CookieValueCacheKey = Base64Helper.Base64Encode(cacheKey);

            return(result);
        }
Пример #5
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public int Login(string name, string pwd)
        {
            Administrator        model = new Administrator();
            string               pwd1  = Base64Helper.Base64Encode(pwd);
            List <Administrator> lie   = db.Queryable <Administrator>().Where(st => st.AName == name && st.Pwd == pwd1).ToList();

            return(lie.Count);
        }
Пример #6
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Register(Administrator model)
        {
            var p = Base64Helper.Base64Encode(model.Pwd);

            model.Pwd = p;
            int i = db.Insertable(model).ExecuteCommand();

            return(i);
        }
Пример #7
0
        public string AuthorizationCode(string clientId)
        {
            if (clientId != _oauthConfig.ClientId)
            {
                return(null);
            }

            var code = Base64Helper.Base64Encode(Guid.NewGuid().ToString()).Substring(0, 10);

            _cacheManager.SetCache(code, "authcode");
            return($"/oauth?code={code}");
        }
Пример #8
0
        public static void TMain(string[] args)
        {
            Base64Helper helper       = new Base64Helper();
            string       url          = "http://www.google.com";
            string       base64Encode = helper.Base64Encode(url);

            Console.WriteLine(base64Encode);

            string base64Decode = helper.Base64Decode(base64Encode);

            Console.WriteLine(base64Decode);
        }
Пример #9
0
        public async Task PostAsync <T>(string link, T model)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(Constants.baseLink);
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Add(Constants.customHeaderKey, Base64Helper.Base64Encode(Constants.customHeaderValue));

                HttpResponseMessage response = await httpClient.PostAsJsonAsync(link, model);

                response.EnsureSuccessStatusCode();
            }
        }
Пример #10
0
        private string CreateRefresh(User user = null)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            var refToken = new RefreshToken()
            {
                Value      = Guid.NewGuid().ToString(),
                Expiration = (int)(DateTime.UtcNow.Add(TimeSpan.FromSeconds(_oauthConfig.LifeSpan)).ToUniversalTime() - origin).TotalSeconds
            };
            var refreshToken = Base64Helper.Base64Encode(refToken.ToJson());

            _cacheManager.SetCache(refreshToken, user?.Login ?? "<app>");
            return(refreshToken);
        }
Пример #11
0
        public void Encrypt_Decrypt_Test()
        {
            var source1 = "helloworld";

            var encrypted1 = Base64Helper.Base64Encode(source1, "utf-8");
            var decrypted1 = Base64Helper.Base64Decode(encrypted1, "utf-8");

            Assert.Equal(source1, decrypted1);


            var source2    = "abc1234";
            var encrypted2 = "YWJjMTIzNA==";

            Assert.Equal(encrypted2, Base64Helper.Base64Encode(source2));

            var encrypted3 = "YnJvdGhlcg==";
            var source3    = "brother";

            Assert.Equal(source3, Base64Helper.Base64Decode(encrypted3));
        }
Пример #12
0
        private async Task Execute(string subject, string htmlMessage, string email)
        {
            try
            {
                htmlMessage = htmlMessage.Replace("%UserId%", Base64Helper.Base64Encode(email));

                var bodyBuilder = new BodyBuilder {
                    HtmlBody = htmlMessage
                };
                var mailMessage = new MimeMessage();
                mailMessage.From.Add(MailboxAddress.Parse(_emailSettings.EmailFrom));
                mailMessage.To.Add(MailboxAddress.Parse(email));
                mailMessage.Subject = subject;
                mailMessage.Body    = bodyBuilder.ToMessageBody();

                await SendMessage(mailMessage);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Cannot send email to {email}");
            }
        }
Пример #13
0
        public static string Generate(string email, string password, string dateTime)
        {
            var token = string.Format("{0}&{1}&{2}", email, password, dateTime);

            return(Base64Helper.Base64Encode(token));
        }
Пример #14
0
 public static string EncodeToken(string token)
 {
     return(Base64Helper.Base64Encode(token));
 }
Пример #15
0
        public GenerateViewModel()
        {
            //BarCode = string.Empty;
            index    = 0;
            JsonList = new ObservableCollection <JsonItem>()
            {
                new JsonItem {
                    Id = index, Checked = true, Key = string.Empty, Value = string.Empty
                }
            };

            DeleteCommand = new Command <int>((id) =>
            {
                if (JsonList.Count == 1)
                {
                    return;
                }
                int i = 0;
                foreach (var item in JsonList)
                {
                    if (item.Id == id)
                    {
                        i = JsonList.IndexOf(item);
                    }
                }
                JsonList.RemoveAt(i);
                //JsonList.RemoveAt(id);
                //index--;
                //for (int i = 0; i < JsonList.Count; i++)
                //{
                //    JsonList[i].Id = i;
                //}
            }, (id) => { return(true); });

            ClearJsonCommand = new Command(() =>
            {
                index    = 0;
                JsonList = new ObservableCollection <JsonItem>()
                {
                    new JsonItem {
                        Id = index, Checked = true, Key = string.Empty, Value = string.Empty
                    }
                };
            }, () => { return(true); });

            GenerateJsonCommand = new Command(() =>
            {
                GenerateJson();
            }, () => { return(true); });

            AddRowCommand = new Command(() =>
            {
                index++;
                JsonList.Add(new JsonItem {
                    Id = index, Checked = true, Key = string.Empty, Value = string.Empty
                });
            }, () => { return(true); });

            ClearPlainTextCommand = new Command(async() =>
            {
                bool action = await Application.Current.MainPage.DisplayAlert("Warning", "请问要清空自由文本吗?", "确定", "取消");
                if (action)
                {
                    PlainText = string.Empty;
                }
            }, () => { return(true); });

            GeneratePlainTextCommand = new Command(() =>
            {
                if (string.IsNullOrWhiteSpace(PlainText))
                {
                    CrossToastPopUp.Current.ShowToastWarning("空字符串,请检查", ToastLength.Long);
                    return;
                }
                else
                {
                    string base64    = Base64Helper.Base64Encode(Encoding.UTF8, PlainText);
                    PlainTextBarCode = base64;
                }
            }, () => { return(true); });

            SaveCommand = new Command <string>(async(code) =>
            {
                if (await GetReadPermissionAsync())
                {
                    MessagingCenter.Send(new object(), "Save", code);
                }
            }, (code) => { return(true); });
        }