public async Task <IActionResult> ResendCode(string userId) { if (!TokenFunctions.HasPhoneTimeElapse(User)) { return(BadRequest("Kindly wait for 5 mins")); } var userFromRepo = await _userManager.FindByIdAsync(userId); if (userFromRepo == null) { return(BadRequest("Bad Request")); } if (await _userManager.IsPhoneNumberConfirmedAsync(userFromRepo)) { return(BadRequest("Your Phone has already been confirmed")); } var userToReturnDto = _mapper.Map <UserToReturnDto>(userFromRepo); userToReturnDto.Code = await _auth.GenerateSMSCode(userFromRepo, userFromRepo.PhoneNumber); //instead of sending the code it will be sent to the phone directly and an Ok will be send back return(Ok(new { user = userToReturnDto, token = TokenFunctions.generateUserToken(userFromRepo, _config, true) })); // return Ok(await _auth.GenerateSMSCode(userFromRepo, userFromRepo.PhoneNumber)); }
public async Task <IActionResult> AddCommentViaEmail(CreateCommentRequestResource createCommentRequestResource) { var newComment = _mapper.Map <Comment>(createCommentRequestResource); var user = await _iUnitOfWork.Users.SaveUser(createCommentRequestResource.Email); var problemBeta = await _iUnitOfWork.ProbBeta.GetEntity(createCommentRequestResource.ProblemId); if (problemBeta == null) { return(BadRequest("We could not find the problem to add a comment")); } newComment.User = user; newComment.ProblemBeta = problemBeta; await _iUnitOfWork.Comments.Add(newComment); await _iUnitOfWork.Complete(); var data = _mapper.Map <CommentResponseResource>(newComment); if (createCommentRequestResource.RememberMe) { var userResponseResource = _mapper.Map <UserResponseResource>(user); return(Ok(new { token = TokenFunctions.generateUserToken(userResponseResource, _config, true), data })); } return(Ok(new { data })); // return Ok(createCommentRequestResource); }
public async Task <IActionResult> Login(LoginRequestResource loginRequestResource) { var user = await _auth.Login(loginRequestResource.Username, loginRequestResource.Pin); if (user == null) { return(Unauthorized()); } var userResponseResource = _mapper.Map <UserResponseResource>(user); return(Ok(new { token = TokenFunctions.generateUserToken(user, _config), user = userResponseResource })); }
public async Task <IActionResult> Login(LoginRequestResource loginRequestResource) { var user = await _unitOfWork.Auth.Login(loginRequestResource.EmailUsername, loginRequestResource.Password); if (user == null) { return(BadRequest("Incorrect username or password")); } var userResponseResource = _mapper.Map <UserResponseResource>(user); return(Ok(new { token = TokenFunctions.generateUserToken(userResponseResource, _config) })); // return Ok(loginRequestResource); }
public async Task <SignInModel> Handle(SignInCommand request, CancellationToken cancellationToken) { var user = await _auth.SignIn(request.EmailAddress, request.Password); if (user == null) { throw new CustomMessageException("Invalid login credentials"); } var response = SignInModel.Create(user); response.Token = TokenFunctions.generateUserToken(user, request.RememberMe.HasValue); return(response); }
public async Task <IActionResult> Register(RegisterRequestResource registerRequestResource) { User newUser = _mapper.Map <User>(registerRequestResource); var user = await _auth.Register(newUser, registerRequestResource.Pin, registerRequestResource.Referer); var userResponseResource = _mapper.Map <UserResponseResource>(user); userResponseResource.Code = await _auth.GenerateSMSCode(user, user.PhoneNumber); // _repo.SaveCode(userResponseResource.Id, userResponseResource.Code); // if(await _repo.SaveAll()) // return CreatedAtRoute(nameof(GetUser), new {UserId = newUser.Id }, userResponseResource); return(Ok(new { user = userResponseResource, token = TokenFunctions.generateUserToken(user, _config, true) })); }
public async Task <IActionResult> LikeProblemBeta(LikeProblemBetaRequestResource likeProblemBetaRequestResource) { // Save the email return the Id var user = await _unitOfWork.Users.SaveUser(likeProblemBetaRequestResource.EmailAddress); var result = await _unitOfWork.Likes.UpdateLike(user.Id, likeProblemBetaRequestResource.ProblemId); await _unitOfWork.Complete(); if (likeProblemBetaRequestResource.RememberMe) { var userResponseResource = _mapper.Map <UserResponseResource>(user); return(Ok(new { token = TokenFunctions.generateUserToken(userResponseResource, _config, true), data = result })); } return(Ok(new { data = result })); }
public async Task <IActionResult> CreateProblemBeta(CreateProblemBeteRequestResource createProblemBeteRequestResource) { var ApplicationProblemBeta = _mapper.Map <CreateProblemBetaRequest>(createProblemBeteRequestResource); var user = await _unitOfWork.ProbBeta.saveProblemBeta(_mapper.Map <ProblemBeta>(ApplicationProblemBeta), ApplicationProblemBeta); await _unitOfWork.Complete(); if (createProblemBeteRequestResource.RememberMe) { var userResponseResource = _mapper.Map <UserResponseResource>(user); return(Ok(new { token = TokenFunctions.generateUserToken(userResponseResource, _config, true) })); } return(NoContent()); // return Ok(_mapper.Map<ProblemBeta>(createProblemBetaRequestResource)); // var keys = Request.Form; // return Ok(createProblemBeteRequestResource.RealImages); }
public async Task <IActionResult> rechargeMobile(MobileRechargeRequestResourse mobileRechargeRequestResource) { var user = await _auth.LoginWithAllData(User.FindFirst(ClaimTypes.NameIdentifier).Value, mobileRechargeRequestResource.Payment.Pin); if (user == null) { return(BadRequest("Incorrect Secret Pin")); } // _payment.transactionMade += _transaction.RecordTransaction; user = _payment.ProcessDatabasePayment(mobileRechargeRequestResource, user); //top up users phone //checked if it worked else //rollback all operations if (!await _repo.SaveAll()) { //return users money } return(Ok(new { user = _mapper.Map <User, UserResponseResource>(user), token = TokenFunctions.generateUserToken(user, _config, true) })); //start with the card }