Esempio n. 1
0
        public ActionResult <SignInResponseContent> SignIn([FromBody] SignInInput signInInput)
        {
            if (signInInput == null)
            {
                return(StatusCode((int)HttpStatusCode.Conflict, new B2CResponseContent("Can not deserialize input claims", HttpStatusCode.BadRequest)));
            }
            if (signInInput.Email.ToLower().Contains("test2"))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, new B2CResponseContent("Test name is not valid, please provide a valid name", HttpStatusCode.BadRequest)));
            }
            SignInResponseContent outputClaims = new SignInResponseContent()
            {
                DisplayName = "User Test 1",
                Email       = signInInput.Email,
                Firstname   = "User1",
                Lastname    = "Test1",
                ValidCreds  = "true"
            };

            if (signInInput.Email.ToLower().Contains("invalidcreds") || signInInput.Password.ToLower().Contains("wrong"))
            {
                outputClaims.ValidCreds = "false";
            }
            return(Ok(outputClaims));
        }
Esempio n. 2
0
        public ActionResult SignIn(SignInInput input)
        {
            if (!ModelState.IsValid)
            {
                input.Password = null;
                input.Login    = null;
                return(View(input));
            }

            var user = userService.Get(input.Login, input.Password);

            //ACHTUNG: remove this in a real app
            if (input.Login == "o" && input.Password == "1")
            {
                user = new User {
                    Login = "******", Roles = new[] { new Role {
                                                     Name = "admin"
                                                 } }
                };
            }

            if (user == null)
            {
                ModelState.AddModelError("", "Try Login: o and Password: 1");
                return(View());
            }

            SignInOwin(user.Login, input.Remember, user.Roles.Select(o => o.Name));


            return(RedirectToAction("index", "home"));
        }
Esempio n. 3
0
        public async Task <SignInOutput> Execute(SignInInput input)
        {
            var encryptedPassword = PasswordEncoder.Encrypt(input.Password);
            var user = await UserRepository.FindUserAsync(input.Login, encryptedPassword);

            return(null != user
                ? new SignInOutput(user, TokenService.CreateToken(user))
                : throw UserNotFound.InvalidCredentials());
        }
Esempio n. 4
0
        public async Task SignIn_ok()
        {
            var input = new SignInInput {
                UserName = "******",
                Password = "******"
            };

            var response = await task.SignIn(input);

            response.StatusCode.Should().Be(StatusCodes.Status200OK);
        }
Esempio n. 5
0
        public async Task SignIn_invalid_credentials()
        {
            var input = new SignInInput {
                UserName = "******",
                Password = "******"
            };

            var response = await task.SignIn(input);

            response.StatusCode.Should().Be(StatusCodes.Status403Forbidden);
        }
Esempio n. 6
0
        public async Task SignIn_user_not_found()
        {
            var input = new SignInInput {
                UserName = Guid.NewGuid().ToString(),
                Password = "******"
            };

            var response = await task.SignIn(input);

            response.StatusCode.Should().Be(StatusCodes.Status404NotFound);
        }
Esempio n. 7
0
        public async Task SignIn_with_empty_password(string password)
        {
            var input = new SignInInput {
                Password = password,
                UserName = faker.Random.String(10)
            };

            var response = await task.SignIn(input);

            response.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
        }
Esempio n. 8
0
        public async Task <IActionResult> SignIn([FromBody] SignInInput input)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await authenticationService.SignIn(input);

            return(Ok());
        }
Esempio n. 9
0
        public async Task <IActionResult> SignIn([FromBody] SignInInput input)
        {
            var result = await _signInManager.PasswordSignInAsync(input.UserName, input.Password, false, false);

            if (result.Succeeded)
            {
                var user = await _userManager.FindByNameAsync(input.UserName);

                if (user == null)
                {
                    return(Unauthorized(new SignInOutput
                    {
                        IsAuthSuccessful = false,
                        ErrorMessage = "Invalid Authentication"
                    }));
                }

                //everything is valid and we need to login the user

                var signinCredentials = GetSigningCredentials();
                var claims            = await GetClaims(user);

                var tokenOptions = new JwtSecurityToken(
                    issuer: _aPISettings.ValidIssuer,
                    audience: _aPISettings.ValidAudience,
                    claims: claims,
                    expires: DateTime.Now.AddDays(30),
                    signingCredentials: signinCredentials);

                var token = new JwtSecurityTokenHandler().WriteToken(tokenOptions);

                return(Ok(new SignInOutput
                {
                    IsAuthSuccessful = true,
                    Token = token,
                    User = new UserOutput
                    {
                        Name = user.Name,
                        Id = user.Id,
                        Email = user.Email,
                        PhoneNo = user.PhoneNumber
                    }
                }));
            }
            else
            {
                return(Unauthorized(new SignInOutput
                {
                    IsAuthSuccessful = false,
                    ErrorMessage = "Invalid Authentication"
                }));
            }
        }
Esempio n. 10
0
        public SignInViewModel(INavigationFacade navigationFacade, IDialogService dialogService)
        {
            _navigationFacade = navigationFacade;
            _dialogService    = dialogService;
            _apiService       = new ApiService();

            SignInCommand      = new RelayCommand(SignIn);
            AccountAndPassword = new SignInInput()
            {
                Account = "arcsinw", Password = "******"
            };
        }
Esempio n. 11
0
        public ListResultDto <SignInListDto> GetSignInRecords(SignInInput input)
        {
            var signInRecords = GetSignInRecordByCondition(input);

            if (signInRecords == null)
            {
                return(new ListResultDto <SignInListDto>());
            }
            var list = signInRecords.MapTo <List <SignInListDto> >();

            SetOtherExtendData(list);
            return(new ListResultDto <SignInListDto>(list));
        }
Esempio n. 12
0
        private IQueryable <SignInRecord> GetSignInRecordByCondition(SignInInput input)
        {
            var query = _signInRepository.GetAll()
                        .WhereIf(!input.Id.IsNullOrEmpty(), o => o.Id == input.Id)
                        .WhereIf(input.BeginTime != null && input.BeginTime.ToString() != "0001/1/1 0:00:00", o => o.BeginTime > input.BeginTime)
                        .WhereIf(input.BeginTime != null && input.BeginTime.ToString() != "0001/1/1 0:00:00" && input.EndTime != null, o => (input.BeginTime < o.BeginTime && o.EndTime < input.EndTime))
                        .Where(o => o.IsDeleted == false);

            query = string.IsNullOrEmpty(input.Sorting)
                        ? query.OrderByDescending(t => t.CreationTime)
                        : query.OrderBy(t => input.Sorting);
            return(query);
        }
Esempio n. 13
0
        public PagedResultDto <SignInListDto> GetPagedSignInRecords(SignInInput input)
        {
            var query = GetSignInRecordByCondition(input);
            var count = query.Count();

            input.SkipCount      = ((input.PIndex ?? 1) - 1) * (input.PSize ?? 10);
            input.MaxResultCount = input.PSize ?? 10;
            input.SkipCount      = input.SkipCount < 0 ? 0 : input.SkipCount;
            var list    = query.PageBy(input).ToList();
            var mapData = list.MapTo <List <SignInListDto> >();

            SetOtherExtendData(mapData);
            return(new PagedResultDto <SignInListDto>(count, mapData)); //list.MapTo<List<SignInListDto>>()
        }
Esempio n. 14
0
        public async Task <IActionResult> SignIn([FromForm] SignInInput input)
        {
            Result <SignInOutput> result = await _authService.SignInAsync(
                input.Email, input.Password);

            if (result.Success)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Esempio n. 15
0
        public ActionResult SignIn(SignInInput input)
        {
            if (!ModelState.IsValid)
            {
                input.Password = null;
                input.Login    = null;
                return(View(input));
            }

            var user = us.Get(input.Login, input.Password);

            if (user == null)
            {
                ModelState.AddModelError("", "Try Login: o and Password: 1");
                // ModelState.AddModelError(Mui.Security, Mui.Invalid_Username_or_Password);
                return(View());
            }

            Session["userId"] = user.Id;
            formsAuth.SignIn(user.Login, input.Remember, user.Roles.Select(o => o.Name));
            var list = bi.Where(o => o.UserId.Equals(user.Id)).SingleOrDefault();

            if (list == null)
            {
                if (user.UserTypeId == 2)
                {
                    return(RedirectToAction("CreateBilling", "UserBillingInformation"));
                }
                else
                {
                    return(RedirectToAction("index", "Application"));
                }
            }
            else
            {
                if (user.UserTypeId == 1)
                {
                    return(RedirectToAction("index", "Home"));
                }
                else if (user.UserTypeId == 2)
                {
                    return(RedirectToAction("index", "Application"));
                }
                else
                {
                    return(RedirectToAction("index", "Home"));
                }
            }
        }
Esempio n. 16
0
        public async Task <IActionResult> SignInUser([FromBody] SignInInput userData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            User user = await authService.SignInUserAsync(userData);

            var tokens = await authService.GenerateAndStoreTokensAsync(user);

            var tokenVM = mapper.Map <TokenVM>((tokens, user));

            return(Ok(tokenVM));
        }
Esempio n. 17
0
        public async Task <User> SignInUserAsync(SignInInput userData)
        {
            var user = await usersRepository.FirstOrDefaultAsync(u => u.Phone == userData.Phone);

            if (user == null)
            {
                throw new BadInputException("user was not found");
            }

            if (!await smsService.CodeIsValidAsync(userData.Phone, userData.SmsCode))
            {
                throw new BadInputException("invalid code");
            }

            return(user);
        }
Esempio n. 18
0
        public async Task <User> SignInUserAsync(SignInInput userData)
        {
            using (var db = new DbContext())
            {
                string hash = GeneratePassword(userData.EMail, userData.Password);

                var user = await db.Users.FirstOrDefaultAsync(u => u.Email == userData.EMail && u.Hash == hash);

                if (user == null)
                {
                    throw new BadInputException(102, "user was not found");
                }

                return(user);
            }
        }
Esempio n. 19
0
        public async Task <bool> SignInAsync(SignInInput accountPassword)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("action", "userLogin");
            dic.Add("user_name", RSAEncryptHelper.PublicEncrypt(accountPassword.Account));
            dic.Add("user_password", RSAEncryptHelper.PublicEncrypt(accountPassword.Password));
            User user = await PostDictionary <User>(dic);

            if (user != null)
            {
                AppEnvironment.Instance.CurrentUser = user;
                return(true);
            }
            return(false);
        }
Esempio n. 20
0
        public void AccountControllerSignInIsCorrect()
        {
            string      testRoute = "https://localhost:5001/api/account/login/";
            SignInInput testInput = new SignInInput
            {
                Username = "******",
                Password = "******"
            };

            var request = new HttpRequestMessage(HttpMethod.Post, testRoute);

            RouteTester routeTester = new RouteTester(_config, request);

            Assert.Equal(typeof(AccountController), routeTester.GetControllerType());
            Assert.Equal(ReflectionHelpers.GetMethodName((AccountController p) => p.SignIn(testInput)), routeTester.GetActionName());
        }
Esempio n. 21
0
        public IActionResult SignIn([FromBody] SignInInput input)
        {
            SignInResponse     response;
            SignInResponseData responseData;

            var command = new SignInCommand(input.UserName, input.Password);
            var result  = RabbitMq.Publish <SignInCommand, Result <SignInResult> >(command);

            if (!result.IsSucceeded)
            {
                return(BadRequest(new ApiResponse(result.Error.Code, result.Error.Description)));
            }

            responseData = new SignInResponseData(result.Data.AccessToken, result.Data.RefreshToken);
            response     = new SignInResponse("OK", "Success", responseData);
            return(Ok(response));
        }
    public ActionResult SignIn(SignInInput input)
    {
        if (!ModelState.IsValid)
        {
            input.Password = null;
            input.Login    = null;
            return(View(input));
        }
        var user = userService.Get(input.Login, input.Password);

        if (user == null)
        {
            ModelState.AddModelError("", "incorrect username or password");
            return(View());
        }
        SignInOwin(user.Login, input.Remember, user.Roles.Select(o => o.Name));
        return(RedirectToAction("index", "home"));
    }
Esempio n. 23
0
        public async Task SignIn(SignInInput input)
        {
            // find user by user-name
            var user = await findByUserName(input.UserName);

            if (user == null)
            {
                throw new ApiError(404, "Username not found!");
            }

            // check password
            var hashedPassword = await hashService.HashText(input.Password);

            if (hashedPassword.Equals(user.Password) == false)
            {
                throw new ApiError(403, "Invalid credentials!");
            }
        }
Esempio n. 24
0
        public async Task <IActionResult> SignInUser([FromBody] SignInInput userData)
        {
            if (!ModelState.IsValid)
            {
                string errors = JsonConvert.SerializeObject(ModelState.Values
                                                            .SelectMany(state => state.Errors)
                                                            .Select(error => error.ErrorMessage));

                throw new BadInputException(101, errors);
            }

            var user = await authService.SignInUserAsync(userData);

            string access_token = authService.GenerateToken(user);

            var tokenVM = mapper.Map <TokenVM>((access_token, user));

            return(Ok(tokenVM));
        }
Esempio n. 25
0
 public ApiResult SignIn([FromBody] SignInInput input)
 {
     return(new DataJob()
     {
         Do = (context, result) =>
         {
             var user =
                 context.Users.FirstOrDefault(u => u.UserName == input.Username && u.Password == input.Password);
             if (user != null)
             {
                 HttpContext.Current.Session["UserId"] = user.Id;
             }
             else
             {
                 result.ResultStatus = ResultStatus.Failed;
                 result.Messages.Add(Models.Resources.Errors.UserNotFound);
             }
         }
     }.Run());
 }
Esempio n. 26
0
        public ActionResult LoginIn(SignInInput input, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                input.Password = null;

                return(View(input));
            }

            var user = userService.Get(input.UserName, input.Password);

            if (user == null)
            {
                ModelState.AddModelError("", "用户名或密码不正确");
                return(View(input));
            }

            formsAuth.SignIn(user.UserName, input.RememberMe, user.Roles.Select(x => x.Name));
            return(RedirectToLocal(returnUrl));
        }
Esempio n. 27
0
        public async Task <IActionResult> SignIn(SignInInput signInInput)
        {
            var result = await _signInManager.PasswordSignInAsync(signInInput.Username, signInInput.Password, isPersistent : false, false);

            if (result.Succeeded)
            {
                var user = await _userManager.FindByNameAsync(signInInput.Username);

                var identityRoles = await _userManager.GetRolesAsync(user);

                var jwtToken = CreateToken(user, identityRoles.ToList());
                return(Ok(new
                {
                    username = user.UserName,
                    jwt = new JwtSecurityTokenHandler().WriteToken(jwtToken),
                    expiration = jwtToken.ValidTo
                }));
            }
            return(BadRequest("Invalid login attempt"));
        }
Esempio n. 28
0
        public ActionResult SignIn(SignInInput input)
        {
            if (!ModelState.IsValid)
            {
                input.Password = null;
                input.Name     = null;
                return(View(input));
            }

            if (!userService.Validate(input.Name, input.Password))
            {
                SetError("Numele sau parola nu sunt introduse corect, va rugam sa mai incercati o data");
                return(View());
            }

            var roles = userService.GetRoles(userService.Get(input.Name).Id);

            formsAuth.SignIn(input.Name, false, roles);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 29
0
        public async Task <IActionResult> SignIn(SignInInput signInInput)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var response = await _identityService.SignIn(signInInput);

            if (!response.IsSuccessful)
            {
                response.Errors.ForEach(s =>
                {
                    ModelState.AddModelError(string.Empty, s);
                });

                return(View());
            }

            return(RedirectToAction(nameof(Index), "Home"));
        }
Esempio n. 30
0
        public ActionResult SignIn(SignInInput input)
        {
            if(!ModelState.IsValid)
            {
                input.Password = null;
                input.Name = null;
                return View(input);
            }

            if (!userService.Validate(input.Name, input.Password))
            {
                SetError("Numele sau parola nu sunt introduse corect, va rugam sa mai incercati o data");
                return View();
            }

            var roles = userService.GetRoles(userService.Get(input.Name).Id);

            formsAuth.SignIn(input.Name, false, roles);

            return RedirectToAction("Index", "Home");
        }
Esempio n. 31
0
        /// <summary>
        /// 获取主页当前时间上课记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string GenerateHomeSignRecordDescription(SignInInput input)
        {
            var signInRecords = GetSignInRecordByCondition(input);
            var sb            = new StringBuilder();
            var result        = (signInRecords != null && signInRecords.Count() > 0) ? sb.AppendLine("今天已经给以下学生上课:") : sb.AppendLine("今天还没有签到 下课后当天记得签到哟");

            if (signInRecords == null)
            {
                return(result.ToString());
            }
            var list = signInRecords.MapTo <List <SignInListDto> >();

            SetOtherExtendData(list);
            var template = "【{0}:{1}~{2}】\r\n";

            foreach (var item in list)
            {
                sb.AppendLine(string.Format(template, item.StudentName, item.BeginTime.ToString("HH:mm"), item.EndTime.ToString("HH:mm")));
            }
            return(sb.ToString());
        }