コード例 #1
0
        public async Task <IActionResult> Register(RegisterModel registerModel)
        {
            if (ModelState.IsValid)
            {
                var users = await _context.GetCollection();

                User user = users.FirstOrDefault(u => u.Email == registerModel.Email);
                if (user == null)
                {
                    var randomWord = GenerateRandomWord();
                    var secretWord = Configuration.GetSection("PasswordStrings").GetSection("EndWord").Value;
                    var password   = _scryptEncoder.Encode(registerModel.Password + randomWord + secretWord);
                    user = new User()
                    {
                        Name       = registerModel.Name,
                        Password   = password,
                        Email      = registerModel.Email,
                        RandomWord = randomWord
                    };
                    _notificationSender.Send("Welcome to our system!", user.Email);
                    await _context.Create(user);
                    await Authenticate(user.Email);

                    return(RedirectToAction("Index", "Main"));
                }
                else
                {
                    ModelState.AddModelError("", "Данная почта занята");
                }
                // await _context.Remove(user.Id);
            }
            return(View("Authorization"));
        }
コード例 #2
0
        public void Post([FromBody] ServiceDto serviceDto)
        {
            var document = new BsonDocument
            {
                { "_Id", mongoContext.GetSpecificCollection("services").Find(new BsonDocument {
                    }).Count() + 1 },                                                                        //AutoIncreament
                { "name", serviceDto.Name },
                { "form", new BsonDocument {
                      { "_Id", serviceDto.FormId }
                  } },
                { "eligibility", new BsonDocument {
                      { "Gender", (int)serviceDto.eligibility.Gender }, { "Nationality", "All" }, { "Grade", (int)serviceDto.eligibility.Grade }
                  } }
            };

            mongoContext.Create("services", document);
        }