コード例 #1
0
ファイル: AdminLogin.cs プロジェクト: hiwamn/Mukta
        public LoginResultDto Execute(LoginDto dto)
        {
            User           user   = unit.User.GetByEmailIncludingRoles(dto.Email);
            LoginResultDto result = new LoginResultDto();

            if (user == null)
            {
                result.Message = Messages.UserNotExist;
            }
            else if (!user.ValidatePassword(dto.Password, _encrypter))
            {
                result.Message = Messages.InvalidPassword;
            }
            else if (user.Status != Enums.EntityStatus.Active.ToInt())
            {
                result.Message = Messages.UserNotActivated;
            }
            else if (user.UserRole == null || !user.UserRole.Any(p => p.RoleId == Roles.Admin.ToInt()))
            {
                result.Message = Messages.AccessDenied;
            }
            else
            {
                result.Object       = DtoBuilder.CreateLoginDto(user);
                result.Object.Token = _jwtHandler.Create(user.Id);
                result.Status       = true;
            }
            return(result);
        }
コード例 #2
0
        public LoginResultDto Execute(RegisterUserDto dto)
        {
            var now = Agent.UnixTimeNow();

            User user = new User()
            {
                Email      = dto.Email,
                FamilyName = dto.FamilyName,
                Name       = dto.Name,
                Mobile     = dto.Email,
                CreatedAt  = now,
                Device     = new List <Device> {
                    new Device {
                        PushId = dto.PushId, CreatedAt = now
                    }
                },
                CityId   = dto.CityId,
                Birthday = dto.Birthday,
                Gender   = dto.Gender,
                Status   = Enums.EntityStatus.WaitingToSendImage.ToInt()
            };

            var referenceUser = unit.User.GetByEmail(dto.ReferenceMobile);

            if (referenceUser != null)
            {
                user.ReferenceId = referenceUser.Id;
            }
            user.SetPassword(dto.Password, encrypter);
            unit.User.Add(user);
            unit.Complete();
            user.City = unit.City.Get(dto.CityId);
            var result = new LoginResultDto
            {
                Object = DtoBuilder.CreateLoginDto(user),
                Status = true
            };

            result.Object.Token = jwtHandler.Create(user.Id);
            return(result);
        }
コード例 #3
0
ファイル: Login.cs プロジェクト: hiwamn/Mukta
        public LoginResultDto Execute(LoginDto dto)
        {
            LoginResultDto result = new LoginResultDto();

            User user = unit.User.GetByEmail(dto.Email);

            if (user == null)
            {
                result.Message = Messages.UserNotExist;
            }
            else
            {
                result.Type = user.Status;
                if (!user.ValidatePassword(dto.Password, _encrypter))
                {
                    result.Message = Messages.InvalidPassword;
                }
                else if (user.Status != Enums.EntityStatus.Active.ToInt())
                {
                    result.Message = GetMessage(user.Status);
                }
                else
                {
                    result.Object       = DtoBuilder.CreateLoginDto(user);
                    result.Object.Token = _jwtHandler.Create(user.Id);
                    if (!unit.Device.IsExist(user.Id, dto.DeviceId))
                    {
                        unit.Device.Add(new Device {
                            PushId = dto.DeviceId, UserId = user.Id, CreatedAt = DateTime.Now.ToUnix()
                        });
                        unit.Complete();
                    }
                    result.Status = true;
                }
            }

            return(result);
        }