コード例 #1
0
 /// <summary>
 /// Add a pagination cursor to the web request in the format required by osu-web.
 /// </summary>
 public static void AddCursor(this WebRequest webRequest, Cursor cursor)
 {
     cursor?.Properties.ForEach(x =>
     {
         webRequest.AddParameter("cursor[" + x.Key + "]", x.Value.ToString());
     });
 }
コード例 #2
0
ファイル: WebRequestExtensions.cs プロジェクト: roridev/osu
 /// <summary>
 /// Add a pagination cursor to the web request in the format required by osu-web.
 /// </summary>
 public static void AddCursor(this WebRequest webRequest, Cursor cursor)
 {
     cursor?.Properties.ForEach(x =>
     {
         webRequest.AddParameter("cursor[" + x.Key + "]", (x.Value as JValue)?.ToString(CultureInfo.InvariantCulture) ?? x.Value.ToString());
     });
 }
コード例 #3
0
        public async Task <ActionResult> Post()
        {
            SignUpRequest credentials;

            using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                credentials = JsonConvert.DeserializeObject <SignUpRequest>(await reader.ReadToEndAsync());
            }

            if (PluginEntry._recaptchaConfig.Enabled)
            {
                using var wc = new WebRequest("https://www.google.com/recaptcha/api/siteverify")
                      {
                          Method = HttpMethod.Post
                      };
                wc.AddParameter("secret", PluginEntry._recaptchaConfig.PrivateKey);
                wc.AddParameter("response", credentials.GCaptchaValidation);
                await wc.PerformAsync();

                var gCaptcha = JsonConvert.DeserializeObject <GCaptchaVerificationResponse>(wc.ResponseString);
                if (!gCaptcha.success)
                {
                    return(Ok(new
                    {
                        code = 450,
                        message = "Recaptcha failed!"
                    }));
                }
            }

            var u = await DbUser.RegisterUser(_context, Permission.From(Permission.DEFAULT), credentials.UserName,
                                              credentials.EMail,
                                              credentials.Password, false);

            if (PluginEntry._sender == null)
            {
                return(Ok(new
                {
                    code = 0,
                    message = "Success"
                }));
            }

            var emailKey = Crypto.RandomString(512);

            u.Status       = UserStatusFlags.Suspended;
            u.StatusReason = "Verification|" + emailKey;
            u.StatusUntil  =
                DateTime.Today + TimeSpan.FromDays(365 * 100); // Suspend for 100 years (or until EMail Verified!)
            _context.Update(u);

            var em = Email
                     .From("*****@*****.**")
                     .To(u.EMail)
                     .Subject("Email Confirmation")
                     .Body("Your EMail has to be Verificated! Please click <a href=\"" +
                           "http://" + _serverConfig.Server.ScreenShotHostname + "/verificate?k" + emailKey
                           + "\">Here</a>!");

            var r = await em.SendAsync();

            if (!r.Successful)
            {
                throw new Exception(
                          $"Failed to send EMail: {r.Successful} {r.MessageId} {r.ErrorMessages.Aggregate((a, b) => a + ", " + b)}"
                          );
            }

            return(Ok(new
            {
                code = 100,
                message = "EMail Verification Pending"
            }));
        }