コード例 #1
0
        public async Task <IActionResult> Register([FromBody] RegisterRequest request)
        {
            var user = new ShopUser {
                UserName = request.Username, Email = request.Username
            };
            var result = await _userManager.CreateAsync(user, request.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation("User created a new account with password.");

                await _userManager.AddToRoleAsync(user, UserRole.User.ToString());

                var code             = EncodeHelper.Base64Encode(await _userManager.GenerateEmailConfirmationTokenAsync(user));
                var confirmationLink = UrlExtensions.EmailConfirmationLink(user.Id, code, _configuration["RedirectDomain"]);
                await _emailSender.SendConfirmationEmailAsync(request.Username, confirmationLink);

                _logger.LogInformation($"Confirmation email was sent to user: {user.Name}");
                return(StatusCode((int)HttpStatusCode.NoContent));
            }

            var errorResponse = new ErrorResponse(ErrorReasons.BadRequest, result.Errors.Select(e => e.Description).FirstOrDefault());

            return(StatusCode((int)HttpStatusCode.BadRequest, errorResponse));
        }
コード例 #2
0
        protected void SaveLastLoginInfo()
        {
            string pwd = this.txtPassword.Text;

            if (string.IsNullOrWhiteSpace(pwd))
            {
                return;
            }
            if (!checkBox1.Checked)
            {
                pwd = string.Empty;
            }
            pwd = EncodeHelper.Base64Encode(EncodeHelper.Base64Encode(pwd));
            PharmacyClientConfig.Config.LastPwd = pwd;

            string login = this.txtName.Text;

            if (string.IsNullOrWhiteSpace(login))
            {
                return;
            }

            PharmacyClientConfig.Config.LastAccount = login;
            PharmacyClientConfig.Config.Pswcheck    = this.checkBox1.Checked;
            ConfigHelper <PharmacyClientConfig> .SaveConfig();
        }
コード例 #3
0
        public override void Test()
        {
            var numbers = "123456";
            //Base64
            var base64 = EncodeHelper.Base64Encode(numbers);

            Console.WriteLine("Base64Encode:{0}", base64);
            Console.WriteLine("Base64Decode:{0}", EncodeHelper.Base64Decode(base64));
            //Unicode
            var character = "这是Unicode编码";
            var unicode   = EncodeHelper.UnicodeEncode(character);

            Console.WriteLine("UnicodeEncode:{0}", unicode);
            Console.WriteLine("UnicodeDecode:{0}", EncodeHelper.UnicodeDecode(unicode));
        }
コード例 #4
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordRequest request)
        {
            var shopUser = await _userManager.FindByEmailAsync(request.Email);

            if (shopUser != null)
            {
                var resetPasswordToken = EncodeHelper.Base64Encode(await _userManager.GeneratePasswordResetTokenAsync(shopUser));
                var resetLink          = UrlExtensions.ResetPasswordLink(shopUser.Id, resetPasswordToken,
                                                                         _configuration["RedirectDomain"]);
                await _emailSender.SendResetPasswordEmailAsync(request.Email, resetLink);

                return(StatusCode((int)HttpStatusCode.OK, "Password recovery confirmation link was sent to your e-mail."));
            }

            return(StatusCode((int)HttpStatusCode.NotFound,
                              new ErrorResponse(ErrorReasons.NotFound, "User was not found.")));
        }
コード例 #5
0
 /// <summary>
 ///  /用户登录校验信息待定
 /// </summary>
 /// <returns></returns>
 private string CheckUser(out User user)
 {
     try
     {
         string msgReturn = string.Empty;
         user = PharmacyDatabaseService.UserLogon(out msgReturn, this.txtName.Text.Trim(), EncodeHelper.Base64Encode(this.txtPassword.Text));
         if (string.IsNullOrWhiteSpace(msgReturn) && user != null)
         {
             AppClientContext.CurrentUser = user;
         }
         else
         {
             msgReturn = string.IsNullOrWhiteSpace(msgReturn) ? "帐户名或密码不正确!" : msgReturn;
         }
         return(msgReturn);
     }
     catch (Exception ex)
     {
         //ex=new Exception("登录失败!",ex);
         user = null;
         return(ex.Message);
     }
 }
コード例 #6
0
        public async Task <PaymentResponse> ProcessPaymentAsync(CheckoutRequest request)
        {
            var jsonContent   = JsonConvert.SerializeObject(request);
            var stringContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", EncodeHelper.Base64Encode(_configuration["PaymentServiceCredentials"]));
            var httpResponse = await httpClient.PostAsync(new Uri(_configuration["PaymentServiceDomain"]), stringContent);

            var response =
                JsonConvert.DeserializeObject <PaymentResponse>(await httpResponse.Content.ReadAsStringAsync());

            response.ResponseCode          = (int)httpResponse.StatusCode;
            response.IsSuccessfullResponse = httpResponse.IsSuccessStatusCode;

            return(response);
        }