Beispiel #1
0
        public ActionResult Register(AccountForRegisterDto account)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.RegisterMessage = "Bir hata meydana geldi";
                return(View());
            }

            if (_accountService.UserExists(account.Email))
            {
                ViewBag.RegisterMessage = "Bu Email başka bir kullanıcı tarafından alınmıştır.";
                return(View());
            }

            Account newAccount = new Account
            {
                FirstName       = account.FirstName,
                LastName        = account.LastName,
                Email           = account.Email,
                RoleID          = 2,
                IsActive        = true,
                MemberDate      = DateTime.Now,
                ProfilPhotoPath = "/Images/DefaultImage.jpg",
                UserName        = account.Email
            };

            _accountService.Register(newAccount, account.Password);
            ViewBag.RegisterMessage = "Üyelik işlemi tamamlanmıştır. Giriş yapabilirsiniz.";
            return(View());
        }
Beispiel #2
0
        public async Task <IActionResult> Register(AccountForRegisterDto accountForRegister)
        {
            if (await _repository.UserExists(accountForRegister.Username))
            {
                return(BadRequest("Użytkownik o takiej nazwie już istnieje"));
            }

            var userToCreate = new Account()
            {
                Username = accountForRegister.Username
            };

            var createdAccount = await _repository.Register(userToCreate, accountForRegister.Password);

            return(StatusCode(201));
        }
Beispiel #3
0
        public async Task <IActionResult> Register(AccountForRegisterDto accountForRegisterDto)
        {
            accountForRegisterDto.Username = accountForRegisterDto.Username.ToLower();

            if (await _repo.UserExists(accountForRegisterDto.Username))
            {
                return(BadRequest("Username already exists"));
            }

            accountForRegisterDto.Status = 1;
            var accountCreate = _mapper.Map <Account>(accountForRegisterDto);

            var createdUser = await _repo.Register(accountCreate, accountForRegisterDto.Password);

            return(Ok());
        }
Beispiel #4
0
        public IActionResult Register(AccountForRegisterDto model)
        {
            // hash the password
            if (!ModelState.IsValid)
            {
                return(BadRequest("An error has occurred."));
            }
            model.Email = model.Email.ToLower();
            if (_accountRepository.AccountExists(model.Email))
            {
                return(BadRequest("Account already exists."));
            }
            var accountToCreate = new Account
            {
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                DateCreated = DateTime.Now
            };
            var createdAccount = _accountRepository.Register(accountToCreate, model.Password);

            return(StatusCode(201));
        }
Beispiel #5
0
        public async Task <IActionResult> Register(AccountForRegisterDto accountForRegisterDto)
        {
            //Remove spaces in front and back and lower the string.
            accountForRegisterDto.Email = accountForRegisterDto.Email.ToLower().Trim();

            //Check if the user exists
            if (await _repo.AccountExists(accountForRegisterDto.Email))
            {
                return(BadRequest(new { error = "Email already exists" }));
            }

            //Make new Account object based on the DTO
            var accountToCreate = new Account
            {
                Email      = accountForRegisterDto.Email,
                FirstName  = accountForRegisterDto.FirstName,
                LastName   = accountForRegisterDto.LastName,
                MiddleName = accountForRegisterDto.MiddleName
            };



            //Create the account
            var createdAccount = await _repo.Register(accountToCreate, accountForRegisterDto.Password);

            //Send verification Email
            Guid verificationId = Guid.NewGuid();
            var  verification   = new Verification {
                Id = verificationId, Account = createdAccount
            };
            await _repo.CreateVerificationInstance(verification);

            EmailService.SendVerificationEmail(createdAccount.Email, verificationId.ToString());

            //Return 201 (created)
            return(StatusCode(201));
        }