public static UserPoco GetUsers(string Username)
        {
            UserPoco g = null;

            g = GetUsers().FirstOrDefault(c => c.Username == Username);
            return(g);
        }
Beispiel #2
0
        public UserPoco GetUserFromApiKey(string apiKey)
        {
            UserPoco res = null;

            //check local cache
            var user = Cache.UserColl.SingleOrDefault(a => a.Key == apiKey);

            if (user.Value == null)
            {
                //check Redis cache
                var userObj = TryGetRedisValue(usercache, apiKey);
                if (userObj.HasValue)
                {
                    res = JsonConvert.DeserializeObject <UserPoco>(userObj.ToString());
                    //if we're here, it wasn't in the local cache (server restarted)
                    SetLocalUser(res);
                }
                else
                {
                    //Go to SQL
                    var usr = wutContext.Users.SingleOrDefault(u => u.ApiKey == apiKey);
                    res = UserPoco.UserToUserPoco(usr);
                    //update local and remote cache
                    if (res != null)
                    {
                        SetUser(res);
                    }
                }
            }
            else
            {
                res = JsonConvert.DeserializeObject <UserPoco>(user.Value);
            }
            return(res);
        }
Beispiel #3
0
        public UserPoco GetLogin(string code, string password)
        {
            var userdb = db.USERS.FirstOrDefault(e => e.CODE == code && e.PASSW == password);

            if (userdb == null)
            {
                return new UserPoco {
                           IsLogin = false
                }
            }
            ;
            else
            {
                UserPoco userpoco = new UserPoco
                {
                    IsLogin   = true,
                    LoginTime = DateTime.Now,
                    Code      = userdb.CODE,
                    ProfileId = Convert.ToInt32(userdb.PROFILEID),
                };

                var musteridb = db.MUSTERI.FirstOrDefault(e => e.MUSNO == userpoco.ProfileId);
                if (musteridb != null)
                {
                    userpoco.FirstName = musteridb.FIRSTNAME;
                    userpoco.LastName  = musteridb.LASTNAME;
                }
                return(userpoco);
            }
        }
Beispiel #4
0
        private static bool AuthAndAddClaims(UserPoco user, HttpActionContext context)
        {
            try
            {
                List <Claim> claims = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, (user.PrimaryEmail ?? Convert.ToString(user.UserId))),
                    new Claim(CustomClaimTypes.UserId, user.UserId.ToString()),
                    new Claim(CustomClaimTypes.ObjectIdentifier, user.UserOID),
                };

                if (user.PrimaryEmail != null)
                {
                    claims.Add(new Claim(ClaimTypes.Email, user.PrimaryEmail));
                }

                // create an identity with the valid claims.
                ClaimsIdentity identity = new ClaimsIdentity(claims, WutAuthTypes.Api);

                // set the context principal.
                context.RequestContext.Principal = new ClaimsPrincipal(new[] { identity });
                return(true);
            }
            catch (Exception ex)
            {
                Logging.WriteDebugInfoToErrorLog("Auth Error", ex);
                return(false);
            }
        }
        public static UserPoco  GetUsers(int id)
        {
            UserPoco g = null;

            g = GetUsers().FirstOrDefault(c => c.SubjectId == id.ToString());
            return(g);
        }
        public async Task <UserPoco> AddAsync(UserPoco poco)
        {
            var parameters = new
            {
                p_last_name               = poco.LastName,
                p_first_name              = poco.FirstName,
                p_middle_name             = poco.MiddleName,
                p_login                   = poco.Login,
                p_need_to_change_pwd      = poco.NeedToChangePwd,
                pwd_hash                  = poco.PwdHash,
                p_refresh_token           = poco.RefreshToken,
                p_token_refresh_timestamp = poco.TokenRefreshTimestamp,
                p_role = poco.Role,
                p_registration_timestamp = poco.RegistrationTimestamp
            };

            var sqlBuilder = new StringBuilder("INSERT into users(");

            sqlBuilder.Append("last_name, first_name, middle_name,");
            sqlBuilder.Append("login, pwd_hash, need_to_change_pwd,");
            sqlBuilder.Append("refresh_token, token_refresh_timestamp, role, registration_timestamp) ");
            sqlBuilder.Append("VALUES(@p_last_name, @p_first_name, @p_middle_name,");
            sqlBuilder.Append("@p_login, @pwd_hash, @p_need_to_change_pwd,");
            sqlBuilder.Append("@p_refresh_token, @p_token_refresh_timestamp, @p_role, @p_registration_timestamp) returning *; ");

            using (IDbConnection conn = Connection)
            {
                var addedDiverPoco = await conn.QueryFirstOrDefaultAsync <UserPoco>(sqlBuilder.ToString(), parameters);

                return(addedDiverPoco);
            }
        }
Beispiel #7
0
        public bool Verify(string user, string pass)
        {
            UserPoco userPoco = null;

            try
            {
                userPoco = _repository.Users.Where(u => u.UserName == user).Single();
            }
            catch
            {
                // user not found
                return(false);
            }

            //byte[] salt = new byte[8];
            //salt[0] = 0x20;
            //salt[0] = 0x21;
            //salt[0] = 0x22;
            //salt[0] = 0x23;
            //salt[0] = 0x24;
            //salt[0] = 0x25;
            //salt[0] = 0x26;
            //salt[0] = 0x27;

            //var hash = ComputeHash(pass, salt);



            return(VerifyHash(pass, userPoco.Pass));
        }
        public async Task <UserPoco> UpdateAsync(UserPoco poco)
        {
            var parameters = new
            {
                p_user_id                 = poco.UserId,
                p_last_name               = poco.LastName,
                p_first_name              = poco.FirstName,
                p_middle_name             = poco.MiddleName,
                p_login                   = poco.Login,
                p_need_to_change_pwd      = poco.NeedToChangePwd,
                p_pwd_hash                = poco.PwdHash,
                p_refresh_token           = poco.RefreshToken,
                p_token_refresh_timestamp = poco.TokenRefreshTimestamp,
                p_role = poco.Role,
                p_registration_timestamp = poco.RegistrationTimestamp
            };

            var sqlBuilder = new StringBuilder("update users set last_name = @p_last_name, ");

            sqlBuilder.Append("first_name = @p_first_name, middle_name = @p_middle_name, login = @p_login, need_to_change_pwd = @p_need_to_change_pwd::boolean, ");
            sqlBuilder.Append("pwd_hash = @p_pwd_hash, refresh_token = @p_refresh_token, token_refresh_timestamp = @p_token_refresh_timestamp, role = @p_role, registration_timestamp = @p_registration_timestamp ");
            sqlBuilder.Append("where user_id = @p_user_id; ");
            sqlBuilder.Append("select * from users where user_id = @p_user_id;");

            using (IDbConnection conn = Connection)
            {
                var updatedUserPoco = await conn.QueryFirstOrDefaultAsync <UserPoco>(sqlBuilder.ToString(), parameters);

                return(updatedUserPoco);
            }
        }
        public async Task <IActionResult> PutUserPoco(int id, UserPoco userPoco)
        {
            if (id != userPoco.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(userPoco).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserPocoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #10
0
 public ActionResult Create(UserPoco model)
 {
     try
     {
         if (model.ID == 0)
         {
             User userEntity = new User
             {
                 ID        = model.ID,
                 Name      = model.Name,
                 LastName  = model.LastName,
                 Email     = model.Email,
                 AddressId = model.AddressId
             };
             _userService.InsertUser(userEntity);
             //IUserService pb = Proxy.ProxyGenerator<IUserService, UserService>.CreateProxy();
             //pb.InsertUser(userEntity);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("index"));
 }
        public async Task <ActionResult <UserPoco> > PostUserPoco(UserPoco userPoco)
        {
            _context.User.Add(userPoco);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserPoco", new { id = userPoco.UserId }, userPoco));
        }
Beispiel #12
0
        public UserPoco ResetApiKey(UserPoco data)
        {
            data.UserId = UserId;
            data.ApiKey = SiteUtils.GenApiKey();

            return(_repo.UpdateUser(data));
        }
        public async Task <UserIdentity> RegisterAsync(RegisterModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (!model.Password.Equals(model.ConfirmPassword))
            {
                throw new ArgumentException("Пароли не совпадают");
            }

            var timestamp    = DateTime.UtcNow.AddMinutes(tokenLifeTimeInMinutes);
            var hash         = GenerateHashPass(model.Password);
            var refreshToken = Guid.NewGuid().ToString();

            var newUser = new UserPoco
            {
                Login                 = model.Login,
                PwdHash               = hash,
                RefreshToken          = refreshToken,
                RegistrationTimestamp = timestamp,
                Role = Roles.Find(r => r.Equals("user")),
                TokenRefreshTimestamp = timestamp
            };

            var added = await _userRepository.AddAsync(newUser);

            var addedUser = _mapper.Map <User>(added);

            var identity = new UserIdentity(addedUser, BuildToken(addedUser, timestamp), refreshToken, timestamp.AddMinutes(tokenLifeTimeInMinutes));

            return(identity);
        }
Beispiel #14
0
        public IEnumerable <AssignedUserPoco> DeleteAssignedUser(int ownerId, UserPoco user)
        {
            var del = _context.UserAssignments.FirstOrDefault(u => u.UserEmail == user.PrimaryEmail && u.WutLink.UserId == ownerId);

            _context.UserAssignments.Remove(del);
            _context.SaveChanges();
            return(GetAssignedUsers(ownerId));
        }
Beispiel #15
0
 public void AddUserAsync(UserPoco user)
 {
     this.AddUser(user);
     if (this.OnUserRetrieved != null)
     {
         this.OnUserRetrieved(user);
     }
 }
Beispiel #16
0
        public static UserPoco GetUserPoco(long userId)
        {
            AngularSignalrDemoEntities context = new AngularSignalrDemoEntities();
            User     user     = context.Users.Where(u => u.UserId == userId).FirstOrDefault <User>();
            UserPoco userPoco = (UserPoco)GetPopulatedPoco(user, typeof(UserPoco));

            return(userPoco);
        }
Beispiel #17
0
        public async Task DeleteUser(UserPoco poco)
        {
            poco.IsDeleted = true;

            await this.UpdateUser(poco);

            await this.AuthenticationService.LogoutAllSessionsWithUserId(poco.UserId);
        }
Beispiel #18
0
 private string MapRole(UserPoco poco)
 {
     if (poco.Roles != null && poco.Roles.Count > 0)
     {
         string[] roles = poco.Roles.Select(role => role.ToString()).ToArray();
         return(string.Join(",", roles));
     }
     return(null);
 }
 /// <summary>
 /// Creates the instance of the <see cref="IUserPoco"/> class.
 /// </summary>
 /// <returns>The instance of the <see cref="IUserPoco"/> class.</returns>
 public virtual IUserPoco CreateUser()
 {
     IUserPoco user = new UserPoco()
     {
         Id = Guid.NewGuid(),
         DateCreated = DateTime.UtcNow,
         DateUpdated = DateTime.UtcNow
     };
     return user;
 }
Beispiel #20
0
        public async Task <SimpleResult> UpdateUserDetail(UserPoco input)
        {
            _context.Entry(input).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(new SimpleResult
            {
                IsSuccess = true
            });
        }
Beispiel #21
0
        public async Task <SimpleResult> SaveUser(UserPoco input, UserManager <UserPoco> userManager)
        {
            await userManager.UpdateAsync(input);

            await _context.SaveChangesAsync();

            return(new SimpleResult
            {
                IsSuccess = true
            });
        }
Beispiel #22
0
        public bool Post(UserPoco userPoco)
        {
            bool result = false;

            try
            {
                this._userModel.AddUser(userPoco);
                result = true;
            }
            catch { }
            return(result);
        }
Beispiel #23
0
        public async Task CreateUser(string username, string password)
        {
            byte[] hashedPassword = HashPassword(password);

            var poco = new UserPoco
            {
                Name     = username,
                Password = hashedPassword
            };

            await this.Database.Insert(poco);
        }
Beispiel #24
0
        public void Update(UserPoco poco)
        {
            bool result = _usersRepository.Update(poco);

            if (result)
            {
                _userHistoriesRepository.Create(poco.Id, poco.Id, "Update Info");
            }
            else
            {
                throw new UpdateException("Update failed!");
            }
        }
Beispiel #25
0
        public ActionResult GetUser(Guid id)
        {
            UserPoco poco = _logic.Get(id);

            if (poco == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(poco));
            }
        }
Beispiel #26
0
        public UserPoco AddUser(UserPoco userPoco)
        {
            AngularSignalrDemoEntities context = new AngularSignalrDemoEntities();
            User user = new User();

            user.UserName  = userPoco.UserName;
            user.Email     = userPoco.Email;
            user.FirstName = userPoco.FirstName;
            user.LastName  = userPoco.LastName;
            context.Users.Add(user);
            context.SaveChanges();

            return(UserPocoFactory.GetUserPoco(user));
        }
Beispiel #27
0
        public UserPoco UpdateUser(UserPoco user)
        {
            try
            {
                var u = _context.Users.SingleOrDefault(usr => usr.UserId == user.UserId);
                u.ApiKey = user.ApiKey;
                _context.SaveChanges();

                return(user);
            }
            catch (Exception ex)
            {
                Logging.WriteDebugInfoToErrorLog("Error updating user", ex);
                return(null);
            }
        }
        public override void Execute()
        {
            var inputMessage = GetMessageAs <CreateUserInputMessage>();
            var user         = new UserPoco
            {
                Login    = inputMessage.Login,
                Password = inputMessage.Password,
                Name     = inputMessage.Name,
                EMail    = inputMessage.EMail
            };

            _context.RepositoryFactory.Get <IUserRepository>().AddUser(user);
            var outputMessage = new CreateUserOutputMessage(inputMessage.ClientId, inputMessage.ChainId, OutputMessageResult.Success);

            _context.QueueManager.SendMessage(AuthSettings.AuthOutputQueue, outputMessage);
        }
Beispiel #29
0
        public JsonResult GetById(int?id)
        {
            UserPoco model = new UserPoco();

            if (id.HasValue && id != 0)
            {
                User userEntity = _userService.GetUser(id.Value);
                model.ID        = userEntity.ID;
                model.Name      = userEntity.Name;
                model.LastName  = userEntity.LastName;
                model.Email     = userEntity.Email;
                model.AddressId = userEntity.AddressId;

                //model.AddressPoco = address.Select(x => new AddressPoco { Id = x.ID, Name = x.Name, userId = x.UserId });
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Beispiel #30
0
        public ActionResult Update(UserPoco employee)
        {
            User userEntity = _userService.GetUser(employee.ID);

            userEntity.Name      = employee.Name;
            userEntity.Email     = employee.Email;
            userEntity.LastName  = employee.LastName;
            userEntity.AddressId = employee.AddressId;

            _userService.UpdateUser(userEntity);
            if (userEntity.ID > 0)
            {
                return(RedirectToAction("index"));
            }

            return(View(employee));
        }