예제 #1
0
        public async Task<HttpResponseMessage> Register(ChangeUserModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid action.");
                }

                // add password to user
                user.User.PasswordHash = user.Password;

                bool isRegistered = await userService.RegisterUser(Mapper.Map<IUser>(user.User), user.Password);

                if (isRegistered)
                {
                    return Request.CreateResponse(HttpStatusCode.Created, "User registered");
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Error while creating new user.");
                }
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }
예제 #2
0
 public void OnSearch(string inventoryNumber)
 {
     if (inventoryNumber != "")
     {
         _searchOperation = OperationBll.GetByFilter(x => x.Store.InventoryNumber == inventoryNumber && x.Guncel);
         if (_searchOperation != null)
         {
             ChangeUserModel = new ChangeUserModel
             {
                 DeviceType      = _searchOperation.Store.Model.DeviceType.Name,
                 InventoryNumber = _searchOperation.Store.InventoryNumber,
                 Model           = _searchOperation.Store.Model.Name,
                 OperationTime   = _searchOperation.OperationTime,
                 Registrant      = _searchOperation.User.Name + " " + _searchOperation.User.Surname,
                 SerialNumber    = _searchOperation.Store.SerialNumber,
                 StoreId         = _searchOperation.StoreId,
                 WarrantyStart   = _searchOperation.Store.WarrantyStart,
                 CompanyId       = _searchOperation.CompanyId,
                 LocationId      = _searchOperation.LocationId,
                 Name            = _searchOperation.Name,
                 Surname         = _searchOperation.Surname,
                 UserId          = LoggedInUser.LoggedUser.Id
             };
         }
         else
         {
             MessageBox.Show("Kayıt Bulunamadı", "Bilgilendirme Mesajı", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
예제 #3
0
        public async Task <HttpResponseMessage> Register(ChangeUserModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid action."));
                }



                // add password to user
                user.User.PasswordHash = user.Password;

                bool isRegistered = await userService.RegisterUser(Mapper.Map <IUser>(user.User), user.Password);

                if (isRegistered)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, "User registered"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Error while creating new user."));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
        public async Task <ActionResult> ChangePassword(ChangeUserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
예제 #5
0
        public async Task <HttpResponseMessage> UpdateUsernameOrMail(ChangeUserModel model)
        {
            try
            {
                IUser result = await userService.UpdateEmailOrUsernameAsync(Mapper.Map <IUser>(model.User), model.Password);


                if (model == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Error while validating user. Update failed"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, result));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
예제 #6
0
        public ActionResult Put([FromBody] ChangeUserModel changeUser)
        {
            //data validation
            if (changeUser.key.Length != changeUser.change.Length || changeUser.dataType.Length != changeUser.key.Length)
            {
                return(Ok("Missing Input"));
            }
            try
            {
                //change user section
                var DBUser = GetAllUsers(changeUser.username, collection).Result;
                if (DBUser.Count > 0)
                {
                    string saltKey = DBUser[0].salt;
                    var    result  = false;
                    for (int i = 0; i < changeUser.key.Length; i++)
                    {
                        switch (changeUser.dataType[i])
                        {
                        case "string":
                            result = ChangeUserInput(changeUser.username, changeUser.collection, changeUser.key[i], changeUser.change[i], null, null, null, saltKey, null, "ChangeUserStr");
                            break;

                        case "int":
                            result = ChangeUserInput(changeUser.username, changeUser.collection, changeUser.key[i], null, Convert.ToInt32(changeUser.change[i]), null, null, saltKey, null, "ChangeUserInt");
                            break;

                        default:
                            break;
                        }
                    }
                    return(Ok(result));
                }
                return(Ok("Error! Non existing user detected!"));
            }
            catch
            {
                return(Ok("Error"));
            }
        }
예제 #7
0
        public async Task <IActionResult> Put(int id, [FromBody] ChangeUserModel changesModel)
        {
            logger.LogInformation("Put action.");
            if (id.ToString() != User.FindFirst("Id")?.Value)
            {
                ModelState.AddModelError("Id", "You do not have the premissions to change this account.");
                return(BadRequest(ModelState));
            }

            logger.LogInformation("Check model for valid.");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userRepository = storage.GetRepository <IUserRepository>();

            User user = null;

            try
            {
                logger.LogInformation("Get a user.");
                user = await userRepository.GetAsync(options =>
                {
                    options.SearchType   = UserSearchTypes.ById;
                    options.UserId       = id;
                    options.WithPassword = true;
                });
            }
            catch (UserNotFoundException ex)
            {
                ModelState.AddModelError("Id", ex.Message);
                return(NotFound(ModelState));
            }

            if (user.Email != changesModel.Email)
            {
                try
                {
                    User userWithSameEmail = await userRepository.GetAsync(options =>
                    {
                        options.SearchType = UserSearchTypes.ByEmail;
                        options.Email      = changesModel.Email;
                    });

                    ModelState.AddModelError("Email", "User with same email actually exist.");
                    return(Conflict(ModelState));
                }
                catch { }
            }

            user.Nickname = changesModel.Nickname;
            user.Email    = changesModel.Email;

            bool willLogout = false;

            if ((changesModel.Password != null) && (changesModel.Password.Length > 8))
            {
                user.Password = Encoding.UTF8.GetString(hashService.GetHash(changesModel.Password));
                willLogout    = true;
            }

            logger.LogInformation("Edit user.");
            userRepository.Edit(user);
            await storage.SaveAsync();

            var responseModel = new
            {
                Nickname = changesModel.Nickname,
                Email    = changesModel.Email,
                Logout   = willLogout
            };

            logger.LogInformation("Return answer.");
            return(Accepted(responseModel));
        }
예제 #8
0
        public async Task<HttpResponseMessage> UpdateUsernameOrMail(string id, ChangeUserModel model)
        {
            try
            {
                IUser result = await userService.UpdateEmailOrUsernameAsync(Mapper.Map<IUser>(model.User), model.Password);

                if (model == null)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Error while validating user. Update failed");
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.OK, result);
                }
            }
            catch (Exception ex)
            {

                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }
        }
예제 #9
0
 public void onClean()
 {
     ChangeUserModel  = new ChangeUserModel();
     SelectedCompany  = new CompanyModel();
     SelectedLocation = new LocationModel();
 }