/// <summary>
        /// This method is goin to authentificate the user
        /// </summary>
        /// <param name="input"> contains all the information required to authentificate the user</param>
        /// <returns>Will return a response model </returns>
        public static ResponseModel SignIn(LogInRequestModel input)
        {
            var task = Task.Run(async() => await RequestHandler.Post(LoginURL, input));

            var result = task.Result;

            if (result.JSON != null)
            {
                var user = JsonConvert.DeserializeObject <User>(result.JSON);
                AppContextSingleton.Instance.AppContext.CurrentConnectedUser = user;
                if (AppContextSingleton.Instance.AppContext.CurrentConnectedUser?.UserGamification?.Badges != null)
                {
                    AppContextSingleton.Instance.AppContext.CurrentConnectedUser.UserGamification.Badges.Reverse();
                    AppContextSingleton.Instance.AppContext.CurrentConnectedUser.UserGameStatsHistory.Reverse();
                    AppContextSingleton.Instance.AppContext.CurrentConnectedUser.UserAuthStats.Reverse();
                }


                // Initialize the socket connection
                WebSocket.Instance.Initialize();

                WebSocket.Instance.LoginCompleted();
            }

            return(result);
        }
Example #2
0
        public async Task <ActionResult> logIn(LogInRequestModel user)
        {
            if (user.username == null)
            {
                return(BadRequest("A username is required to login."));
            }

            if (user.password == null)
            {
                return(BadRequest("A password is required to login."));
            }

            SupportUsers checkUser = await adminRepository.getAdmin(user.username.Trim());

            /* If null, no user with that username exists.*/
            if (checkUser == null)
            {
                return(NotFound("Nobody with that username exists."));
            }

            /* Verify correct password has been entered.*/
            if (verifyHash(SHA256.Create(), user.password, checkUser.Password))
            {
                return(Ok());
            }
            else
            {
                return(Unauthorized("Password is incorrect."));
            }
        }
Example #3
0
        public async Task <LogInResponseModel> LogInAsync(LogInRequestModel logInRequestModel)
        {
            var response = new LogInResponseModel {
                IsSuccessful = false
            };

            UserData userData = await applicationUserRepository.FindByEmailAsync(logInRequestModel.Email.Normalize());

            if (userData == null)
            {
                response.Message = "Account with this email doesn`t exists";
            }
            else if (!await applicationUserRepository.CheckPasswordAsync(
                         logInRequestModel.Email,
                         logInRequestModel.Password))
            {
                response.Message = "Wrong Password";
            }
            else
            {
                string token      = javascriptWebTokenFactory.Create(userData.Id);
                var    sessionDto = new SessionData
                {
                    UserId = userData.Id,
                    Token  = token
                };
                await sessionRepository.CreateAsync(sessionDto);

                response.Token        = token;
                response.IsSuccessful = true;
            }
            return(response);
        }
Example #4
0
        public async Task <ActionResult <UserResponseModel> > logIn(LogInRequestModel user)
        {
            Users checkUser = await userGymMovesRepository.getUser(user.username.Trim());

            /* If null, no user with that username exists.*/
            if (checkUser == null)
            {
                return(NotFound("Nobody with that username exists."));
            }

            /* Verify correct password has been entered.*/
            if (verifyHash(SHA256.Create(), user.password + checkUser.Salt, checkUser.Password))
            {
                UserResponseModel response = new UserResponseModel();
                response.userType    = checkUser.UserType;
                response.name        = checkUser.Name;
                response.gymMemberID = checkUser.MembershipId;
                response.gymID       = checkUser.GymIdForeignKey;

                return(Ok(response));
            }
            else
            {
                return(Unauthorized("Password is incorrect."));
            }
        }
        protected override async Task <IFailable <CredentialsDataModel> > LogInAsync([ParameterDocumentation("Πληροφορίες σχετικά με τα στοιχεία σύνδεσης")] LogInRequestModel model)
        {
            var result = await iPetrosDI.GetDataStorage.LogInAsync(model);

            if (!result.Successful)
            {
                return new Failable <CredentialsDataModel>()
                       {
                           ErrorMessage = result.ErrorMessage
                       }
            }
            ;

            iPetrosDI.ConnectedUser = result.Result;

            return(new Failable <CredentialsDataModel>()
            {
                Result = new CredentialsDataModel()
                {
                    FirstName = result.Result.FirstName,
                    LastName = result.Result.LastName,
                    Username = result.Result.Username,
                    Email = result.Result.Email,
                    PhoneNumber = result.Result.PhoneNumber
                }
            });
        }

        #endregion
    }
Example #6
0
        public LoginViewModel()
        {
            ConnectionCommand         = new RelayCommand <object>(Login);
            LoginWithOtherAuthCommand = new RelayCommand <string>(LoginWithOtherProvider);
            LoginRequestModel         = new LogInRequestModel();
            authentificationToken     = string.Empty;

            InitializeServices();
            WebSocket.Instance.ReceivedUserInformation += OnUserInformationReceived;
        }
Example #7
0
        public async Task LoginTest()
        {
            LogInRequestModel  logInRequestModel = CreateLogInRequestModel();
            LogInResponseModel expected          = CreateLogInResponseModel();

            SetupAccountServiceLoginMock(logInRequestModel, expected);

            var actual = (JsonResult)await accountApiController.Login(logInRequestModel);

            Assert.AreEqual(expected, actual.Value);
        }
Example #8
0
        public IActionResult LogIn([FromBody] LogInRequestModel loginRequestData)
        {
            var loginData = new LogInDataDto
            {
                Username = loginRequestData.UserName,
                Password = loginRequestData.Password
            };

            var token = logInService.LogIn(loginData);

            return(Ok(new AuthenticationResponseModel {
                Token = token.Value
            }));
        }
Example #9
0
        public async Task <Failable <StaffMemberDataModel> > LogInAsync(LogInRequestModel model)
        {
            try
            {
                var result = await DbContext.StaffMembers.FirstOrDefaultAsync(x => x.Username == model.Username && x.Password == model.Password);

                return(new Failable <StaffMemberDataModel>()
                {
                    ErrorMessage = result == null ? "Λανθασμένα στοιχεία σύνδεσης" : null,
                    Result = result
                });
            }
            catch (Exception ex)
            {
                return(ex);
            }
        }
Example #10
0
        public async Task <IActionResult> LogIn([FromBody] LogInRequestModel model)
        {
            if (ModelState.IsValid)
            {
                LogInActionResult result = await _accountService.LogInActionAsync(model.Email, model.Password, model.RememberMe);

                if (result == LogInActionResult.TwoFactorRequired)
                {
                    return(BadRequest(new LogInResponseModel
                    {
                        ExpectedError = true,
                        TwoFactorRequired = true
                    }));
                }

                if (result == LogInActionResult.Success)
                {
                    _antiforgery.AddAntiforgeryCookies(HttpContext);

                    return(Ok());
                }

                // Don't reveal whether email or password was invalid
                return(BadRequest(new LogInResponseModel
                {
                    ExpectedError = true,
                    ErrorMessage = Strings.ErrorMessage_LogIn_Failed
                }));
            }

            return(BadRequest(new LogInResponseModel
            {
                ExpectedError = true,
                ModelState = new SerializableError(ModelState)
            }));
        }
Example #11
0
 public async Task <IActionResult> Login(LogInRequestModel logInRequestModel)
 => Json(await accountService.LogInAsync(logInRequestModel));
Example #12
0
 private void SetupAccountServiceLoginMock(LogInRequestModel logInRequestModel, LogInResponseModel logInResponseModel)
 => accountServiceMock
 .Setup(service => service.LogInAsync(logInRequestModel))
 .ReturnsAsync(logInResponseModel);