コード例 #1
0
        public async Task <IActionResult> SendVerificationCode([FromBody] User_Verify_BindingModel collection)
        {
            if (string.IsNullOrWhiteSpace(collection.DeviceId))
            {
                return(BadRequest(_stringLocalizer[SharedResource.DeviceIdNotFound]));
            }
            try {
                var model = _mapper.Map <User_SetVerificationCode_Schema>(collection);
                model.VerificationCode = _randomGenerator.Create("****");
                await _userService.SetVerificationCodeAsync(model);

                switch (model.StatusCode)
                {
                case 400:
                    return(BadRequest(_stringLocalizer[SharedResource.DeviceIdNotFound]));

                case 410:
                    return(BadRequest(_stringLocalizer[SharedResource.UserIsNotActive]));

                case 416:
                    return(BadRequest(_stringLocalizer["u must register a cell phone first"]));

                case 417:
                    return(BadRequest(_stringLocalizer["CellPhone does not match"]));

                case 418:
                    return(BadRequest(_stringLocalizer["u must register an email first"]));

                case 419:
                    return(BadRequest(_stringLocalizer["Email does not match"]));

                case 200: {
                    if (!string.IsNullOrWhiteSpace(model.CellPhone))
                    {
                        // Send SMS
                        _smsService.Send(model.CellPhone, $"{_stringLocalizer["This is your verification code"]} {model.VerificationCode}");
                    }
                    if (!string.IsNullOrWhiteSpace(model.Email))
                    {
                        // Send Email
                        _emailService.Send(model.CellPhone, _stringLocalizer["VerificationCode"],
                                           $"{_stringLocalizer["This is your verification code"]} {model.VerificationCode}");
                    }
                    return(Ok());
                }
                }
            }
            catch (Exception ex) {
                Log.Error(ex, MethodBase.GetCurrentMethod().Name);
                await _exceptionService.InsertAsync(ex, URL, IP);
            }
            return(InternalServerError());
        }
コード例 #2
0
        protected override DataSet CreateDataSet()
        {
            DataSet result = new DataSet();

            if (!String.IsNullOrEmpty(ConnectionString))
            {
                MeGonnaBeRandomConnectionStringBuilder sb = new MeGonnaBeRandomConnectionStringBuilder();
                sb.ConnectionString = ConnectionString;

                int count = sb.RowCount;

                List <IRandomGenerator> generators = new List <IRandomGenerator>();
                DataTable table = new DataTable("Table1");

                foreach (string str in sb.Generators)
                {
                    string[] args = str.Split(':').Select(t => t.Trim()).ToArray();

                    IRandomGenerator generator = Utils.Get(args[1]);
                    if (generator != null)
                    {
                        generator            = generator.Create();
                        generator.ColumnName = args[0];


                        table.Columns.Add(generator.ColumnName, generator.Type);

                        generators.Add(generator);
                    }
                }

                for (int i = 0; i < count; i++)
                {
                    DataRow row = table.NewRow();
                    foreach (IRandomGenerator generator in generators)
                    {
                        row[generator.ColumnName] = generator.Next();
                    }
                    table.Rows.Add(row);
                }



                result.Tables.Add(table);
            }

            return(result);
        }
コード例 #3
0
        public void RandomGenerator()
        {
            var number = _randomGenerator.Create("***");

            Assert.IsTrue(number >= 100 && number <= 999);
        }