示例#1
0
        public int EmailActivate(ActivateModel model, string subject = "激活验证码", string body = null)
        {
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");
            mail.To.Add(model.Email);
            mail.Subject    = subject;
            mail.IsBodyHtml = true;
            int captcha = new Random().Next(1111, 9999);

            if (body == null)
            {
                body = $@"亲爱的一起帮用户——{model.UserName},您好,你的验证码是{captcha},您也可以点击下面的链接重置密码,
                http://localhost:59397/Password/Reset/Captcha={captcha}?Email={model.Email}";
            }
            mail.Body = body;
            SmtpClient client = new SmtpClient("smtp.163.com");

            client.Port        = 25;
            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "yz17bang");
            client.EnableSsl   = false;


            client.Send(mail);

            return(captcha);
        }
        public async Task <IActionResult> Activate(ActivateModel model)
        {
            AccountStatusPair asp = await repository.GetAccountStatus(Request, Response);

            if (asp.status != AccountStatus.Inactive)
            {
                return(RedirectToAction("Index"));
            }
            else if (ModelState.IsValid)
            {
                if (await repository.VerifyAccount(asp.account.Email, model.Code))
                {
                    return(RedirectToAction("LogIn"));
                }
            }
            return(View(new ActivateModel("", true)));
        }
示例#3
0
        public void FloatingLicensingTest()
        {
            var activateToken = activateDeactivate;
            var res1          = Key.Activate(token: activateToken, parameters: new ActivateModel()
            {
                Key = "GEBNC-WZZJD-VJIHG-GCMVD", ProductId = 3349, Sign = true, MachineCode = "test", Metadata = true, FloatingTimeInterval = 10
            });

            Key.Deactivate(activateToken, new DeactivateModel {
                Key = "GEBNC-WZZJD-VJIHG-GCMVD", ProductId = 3349, MachineCode = "test", Floating = true
            });

            var res2 = Key.Activate(token: activateToken, parameters: new ActivateModel()
            {
                Key = "GEBNC-WZZJD-VJIHG-GCMVD", ProductId = 3349, Sign = true, MachineCode = Helpers.GetMachineCode(), Metadata = true, FloatingTimeInterval = 10, MaxOverdraft = 1
            });

            Assert.IsTrue(Helpers.IsOnRightMachine(res2.LicenseKey, isFloatingLicense: true, allowOverdraft: true));

            var activateModel = new ActivateModel()
            {
                Key = "GEBNC-WZZJD-VJIHG-GCMVD", ProductId = 3349, Sign = true, MachineCode = Helpers.GetMachineCode(), Metadata = true, FloatingTimeInterval = 10, MaxOverdraft = 1
            };
            var activateResult = Key.Activate(token: activateToken, parameters: activateModel);

            if (activateResult != null && activateResult.Result == ResultType.Success)
            {
                var info = Helpers.GetFloatingLicenseInformation(activateModel, activateResult);

                System.Diagnostics.Debug.WriteLine(info.AvailableDevices);
                System.Diagnostics.Debug.WriteLine(info.UsedDevices);
                System.Diagnostics.Debug.WriteLine(info.OverdraftDevices);

                var a = info.AvailableDevices;
            }
            else
            {
                Assert.Fail();
            }

            //var result = Key.Activate(token: activateToken, parameters: new ActivateModel() { Key = "GEBNC-WZZJD-VJIHG-GCMVD", ProductId = 3349, Sign = true, MachineCode = Helpers.GetMachineCode(), Metadata = true, FloatingTimeInterval = 100 });

            //Assert.IsTrue(result.LicenseKey.ActivatedMachines[0].Mid.StartsWith("floating:"));

            //Assert.IsTrue(Helpers.IsOnRightMachine(result.LicenseKey, isFloatingLicense: true));
        }
示例#4
0
 /// <summary>
 /// This method will perform a key activation, similar to Activate [Web API 2].
 /// In contrast to key validation, key activation is not read only since it can
 /// change license key data depending on configurations such as trial activation,
 /// etc. If trial activation is enabled, a key can be altered. Information that
 /// is retrieved can be signed by the server to be able to keep validate keys
 /// without Internet connection. Please keep in mind that the Feature lock can
 /// be used to restrict the fields that can be shown in the result (fieldsToReturn).
 /// More about this in Remarks.
 /// https://app.cryptolens.io/docs/api/v3/Activate
 /// </summary>
 /// <param name="token">The access token. Read more at https://app.cryptolens.io/docs/api/v3/Auth </param>
 /// <param name="parameters">The parameters that the method needs.</param>
 /// <returns>A <see cref="BasicResult"/> or null.</returns>
 /// <remarks>
 /// The feature lock value is used to store the filedsToReturn value. If you set a certain value in the feature lock, it will be prioritized higher than the fieldsToReturn parameter.<br></br>
 /// • To compute the value of the feature lock, please use the Hide column, for those fields that you want to omit in the result above.<br></br>
 /// • If the ActivatedMachines is hidden, only the current machine code will be included(used during this particular activation). Otherwise, all machine codes will be included.
 /// </remarks>
 /// <example>
 /// Assuming that you've created a key in the SKM platform that has maximum number of machines set to anything greater than zero, we can run the following code:
 /// <code language="csharp" title="Activation example">
 /// var auth = "{access token with permission to access the activate method}"
 /// var result = Key.Activate(token: auth, parameters: new ActivateModel()
 /// {
 ///     Key = "GEBNC-WZZJD-VJIHG-GCMVD",
 ///     ProductId = 3349,
 ///     Sign = true,
 ///     MachineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
 /// });
 ///
 /// if(result == null || result.Result == ResultType.Error)
 /// {
 ///     // an error occured or the key is invalid or it cannot be activated
 ///     // (eg. the limit of activated devices was achieved)
 /// }
 /// // everything went fine if we are here!
 /// </code>
 /// </example>
 public static KeyInfoResult Activate(string token, ActivateModel parameters)
 {
     if (parameters != null)
     {
         if (parameters.OSInfo == null)
         {
             try
             {
                 parameters.OSInfo = Helpers.GetOSStats();
             }
             catch { }
         }
         else if (parameters.OSInfo == "")
         {
             parameters.OSInfo = null;
         }
     }
     return(HelperMethods.SendRequestToWebAPI3 <KeyInfoResult>(parameters, "/key/activate/", token));
 }
        public async Task <ActionResult> Activate([FromBody] ActivateModel activateModel)
        {
            if (string.IsNullOrEmpty(activateModel.UserId))
            {
                activateModel.UserId = Guid.NewGuid().ToString();
                await authService.AnonymousUser(activateModel.UserId);
            }

            var user = await authService.EnsureAndGetUserAsync();

            if (user == null && !string.IsNullOrEmpty(activateModel.UserId))
            {
                user = await userRepository.RegisterUser(activateModel.UserId, null, null, null);
            }

            var bag = await bagRepository.GetUnusedAsync(activateModel.BagId);

            if (bag == null)
            {
                return(Ok(new ActivateResultModel
                {
                    Status = ActivativateStatus.Unknown,
                    UserId = activateModel.UserId
                }));
            }

            await bagRepository.DeleteAsync(bag);

            var newBag = new Bag(activateModel.UserId, bag.BagId)
            {
                CreatedDate = bag.CreatedDate,
                Status      = BagStatus.Active
            };

            await bagRepository.AddOrUpdateAsync(newBag);

            return(Ok(new ActivateResultModel
            {
                Status = ActivativateStatus.OK,
                UserId = newBag.UserId,
                BagId = newBag.BagId
            }));
        }
        public ActionResult Activate()
        {
            // Redirect if the user is logged in already
            if (IdentityModel.CurrentUserLoggedIn)
            {
                return(RedirectToAction("Account", "Logged"));
            }

            var model = new ActivateModel
            {
                // Set default
                Gender = 0
            };

            string token;

            try
            {
                // Get the token from the RouteData
                token = SqlInjection.SafeSqlLiteral(Url.RequestContext.RouteData.Values["id"].ToString());
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch (Exception)
            // ReSharper restore EmptyGeneralCatchClause
            {
                return(RedirectToAction("Index", "Home"));
            }

            // Redirect if the token is invalid or missing
            if (String.IsNullOrEmpty(token) || token.Length != 32)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (!ActivateModel.CheckAccount(token))
            {
                return(RedirectToAction("Account", "Logged"));
            }

            // Get values form the database
            model.GetValues(token);

            return(View(model));
        }
        public async Task <IActionResult> ResendMail()
        {
            AccountStatusPair asp = await repository.GetAccountStatus(Request, Response);

            if (asp.status != AccountStatus.Inactive)
            {
                return(RedirectToAction("Index"));
            }
            asp.account.VerificationCode = ActivateModel.GenerateCode();
            repository.ForceSave();
            try
            {
                // Services.Email.SendVerification(userAccount.Email, userAccount.VerificationCode.ToString(), "A new verification code was requested.");
            }
            catch (Exception ex)
            {
                logger.LogError($"AUTO-MAIL FAILED: {ex.Message}");
                return(RedirectToAction("Error"));
            }
            logger.LogInformation($"User @{asp.account.Username} (ID: {asp.account.Id}) requested a new verification code to email {asp.account.Email} (Verification code: {asp.account.VerificationCode})");
            return(RedirectToAction("Activate", new { Resent = true }));
        }
        public ActionResult Activate(ActivateModel model)
        {
            string token;

            try
            {
                // Get the token from the RouteData
                token = SqlInjection.SafeSqlLiteral(Url.RequestContext.RouteData.Values["id"].ToString());
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch (Exception)
            // ReSharper restore EmptyGeneralCatchClause
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (String.IsNullOrEmpty(token) || token.Length != 32)
            {
                return(RedirectToAction("Index", "Home"));
            }
            // Load in values from database
            model.GetValues(token);

            // Make Postal code upperCase, remove spaces and encrypt the string
            model.PostalCode =
                Crypt.StringEncrypt(
                    SqlInjection.SafeSqlLiteral(StringManipulation.ToUpperFast(model.PostalCode))
                    .Replace(" ", string.Empty), model.Pepper);
            model.HouseNumber = Crypt.StringEncrypt(SqlInjection.SafeSqlLiteral(model.HouseNumber), model.Pepper);

            // If UpdateAccount fails show error page
            if (!model.UpdateAccount())
            {
                return(View("Error"));
            }
            // Make cookie for user
            Cookies.MakeCookie(model.Mail, model.Id.ToString(CultureInfo.InvariantCulture), "0");
            return(RedirectToAction("Account", "Logged"));
        }
示例#9
0
        public ActionResult FPS(ActivateModel model)
        {
            if (UserModelsRepository.Instance.IsSimplePassword(model.NewPassword))
            {
                ModelState.AddModelError("", "The new password is too simple. " +
                                         "Passwords must be at least 8 characters in length. " +
                                         "Passwords must contain: " +
                                         "a minimum of 1 lower case letter [a-z] and a minimum of 1 upper case letter [A-Z] and " +
                                         "a minimum of 1 numeric character [0-9] and a minimum of 1 special character: " +
                                         "~`!@#$%^&*()-_+={}[]|\\;:\"<>,./?");
                return(View("Activate", model));
            }
            else
            {
                if (UserModelsRepository.Instance.FPS(model))
                {
                    return(RedirectToAction("LogON"));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#10
0
        // **************************************
        // URL: /Account/Update/FPS/key
        // **************************************
        public ActionResult FPS(string key)
        {
            string msg;
            CUser  clUser = new CUser(null, LocalData.CSDbUsers(), LocalData.LogPath());
            STUser stUser;
            int    ret = clUser.GetRecordByUserKey(key, out stUser, out msg);

            if (ret != 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (stUser.newemailkey != key)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ActivateModel model = new ActivateModel();

            model.Key = key;
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return(View("Activate", model));
        }
示例#11
0
        /// <summary>
        /// This method is similar to <see cref="Key.Activate(string, ActivateModel)"/> with the only exception that it will return a license key signed with the new protocol.
        /// <b>Note:</b> it's better to use this method, especially if you target Mono/Unity.<br/>
        /// In order to get the license key, you can call <see cref="LicenseKey.FromResponse(string, RawResponse)"/>.
        /// </summary>
        public static RawResponse Activate(string token, int productId, string key, string machineCode = "", bool metadata = false,
                                           int floatingTimeInterval = 0, int maxOverdraft = 0, string OSInfo = null, string friendlyName = "")
        {
            var parameters = new ActivateModel()
            {
                ProductId            = productId,
                Key                  = key,
                MachineCode          = machineCode,
                Metadata             = metadata,
                FloatingTimeInterval = floatingTimeInterval,
                MaxOverdraft         = maxOverdraft,
                Sign                 = true,
                SignMethod           = SignMethod.StringSign,
                OSInfo               = OSInfo,
                FriendlyName         = friendlyName
            };

            if (parameters != null)
            {
                if (parameters.OSInfo == null)
                {
                    try
                    {
                        parameters.OSInfo = Helpers.GetOSStats();
                    }
                    catch { }
                }
                else if (parameters.OSInfo == "")
                {
                    parameters.OSInfo = null;
                }
            }

            var res = HelperMethods.SendRequestToWebAPI3 <RawResponse>(parameters, "/key/activate/", token, modelVersion: 2);

            return(res);
        }
示例#12
0
 /// <summary>
 /// Returns floating license related information.
 /// </summary>
 public static FloatingLicenseInformation GetFloatingLicenseInformation(ActivateModel activationModel, KeyInfoResult activationResult)
 {
     return(GetFloatingLicenseInformation(activationModel.MaxOverdraft,
                                          activationResult.LicenseKey.MaxNoOfMachines,
                                          activationResult.Metadata.UsedFloatingMachines));
 }
示例#13
0
 /// <summary>
 /// This method will perform a key activation, similar to Activate [Web API 2].
 /// In contrast to key validation, key activation is not read only since it can
 /// change license key data depending on configurations such as trial activation,
 /// etc. If trial activation is enabled, a key can be altered. Information that
 /// is retrieved can be signed by the server to be able to keep validate keys
 /// without Internet connection. Please keep in mind that the Feature lock can
 /// be used to restrict the fields that can be shown in the result (fieldsToReturn).
 /// More about this in Remarks.
 /// https://app.cryptolens.io/docs/api/v3/Activate
 /// </summary>
 /// <param name="token">The access token. Read more at https://app.cryptolens.io/docs/api/v3/Auth </param>
 /// <param name="parameters">The parameters that the method needs.</param>
 /// <returns>A <see cref="BasicResult"/> or null.</returns>
 /// <remarks>
 /// The feature lock value is used to store the filedsToReturn value. If you set a certain value in the feature lock, it will be prioritized higher than the fieldsToReturn parameter.<br></br>
 /// • To compute the value of the feature lock, please use the Hide column, for those fields that you want to omit in the result above.<br></br>
 /// • If the ActivatedMachines is hidden, only the current machine code will be included(used during this particular activation). Otherwise, all machine codes will be included.
 /// </remarks>
 /// <example>
 /// Assuming that you've created a key in the SKM platform that has maximum number of machines set to anything greater than zero, we can run the following code:
 /// <code language="csharp" title="Activation example">
 /// var auth = "{access token with permission to access the activate method}"
 /// var result = Key.Activate(token: auth, parameters: new ActivateModel()
 /// {
 ///     Key = "GEBNC-WZZJD-VJIHG-GCMVD",
 ///     ProductId = 3349,
 ///     Sign = true,
 ///     MachineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
 /// });
 ///
 /// if(result == null || result.Result == ResultType.Error)
 /// {
 ///     // an error occured or the key is invalid or it cannot be activated
 ///     // (eg. the limit of activated devices was achieved)
 /// }
 /// // everything went fine if we are here!
 /// </code>
 /// </example>
 public static KeyInfoResult Activate(string token, ActivateModel parameters)
 {
     return(HelperMethods.SendRequestToWebAPI3 <KeyInfoResult>(parameters, "/key/activate/", token));
 }
 public async Task Activate(ActivateModel model)
 {
     await _accountService.ActivateUser(Context.ApiKey, model.ActivationCode);
 }