public IActionResult createuser(UserPayload userpayload) { SucceedInfomation succeedinfomation = new SucceedInfomation(); if (userpayload.password.Length < 6) { succeedinfomation.Issucceed = false; succeedinfomation.SucceedDetail = "password must be atleast 6 character"; return(Ok(succeedinfomation)); } // find user if exist return false user finduser = _Context.users.FirstOrDefault(x => x.username == userpayload.username); if (finduser != null) { succeedinfomation.Issucceed = false; succeedinfomation.SucceedDetail = "username exited"; } //generate salt and hash SaltHashed salthashed = _authservice.provideSaltHashed(userpayload.password); user Newuser = new user() { username = userpayload.username, userfirstname = userpayload.userfirstname, userlastname = userpayload.userlastname, usersalt = salthashed.StrSalt, userhashed = salthashed.StrHashed, roleid = 2 }; _Context.users.Add(Newuser); _Context.SaveChanges(); return(Ok(succeedinfomation)); }
public ActionResult <User> Update([FromBody] UserPayload payload) { try { if (payload.Id.HasValue) { var userToUpdate = _db.Users.SingleOrDefault(user => payload.Id.Value == user.Id); userToUpdate.FirstName = payload.FirstName; userToUpdate.LastName = payload.LastName; userToUpdate.Email = payload.Email; userToUpdate.Gender = payload.Gender; _db.SaveChanges(); return(Ok(userToUpdate)); } else { return(new StatusCodeResult(StatusCodes.Status400BadRequest)); } } catch (Exception ex) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public ActionResult <User> Update([FromBody] UserPayload payload) { String[] authorization = Request.Headers["authorization"].ToString().Split(" "); String token = authorization[authorization.Length - 1]; String id = ((JwtSecurityToken) new JwtSecurityTokenHandler().ReadToken(token)).Claims.First(claim => claim.Type == "id").Value; try { var selectedUser = _db.Users.Single(u => u.Id == Int32.Parse(id)); selectedUser.FirstName = payload.FirstName; selectedUser.LastName = payload.LastName; selectedUser.Email = payload.Email; selectedUser.Gender = payload.Gender; selectedUser.DateOfBirth = payload.DateOfBirth; selectedUser.City = payload.City; selectedUser.Country = payload.Country; selectedUser.ImgUrl = payload.ImgUrl; _db.SaveChanges(); return(Ok(new { message = "success" })); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public ActionResult SetInfo([FromBody] UserPayload payload) { int uid = Int32.Parse(payload.Id); var token = HttpContext.Request.Headers["token"].ToString(); var validation = ValidateJwtToken(token); if (validation != null) { if (uid != validation) { return(new StatusCodeResult(StatusCodes.Status401Unauthorized)); } try { var user = _db.Users.Single(user => uid == user.Id); user.ProfilePic = payload.ProfilePic; user.Age = Int32.Parse(payload.Age); _db.SaveChanges(); return(Ok(user)); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } } else { return(new StatusCodeResult(StatusCodes.Status401Unauthorized)); } }
public void getUserStatTest() { UserPayload user = new UserPayload("jintian"); ResponseWrapper content = client.getUserStat(user); Assert.AreEqual(content.responseCode, HttpStatusCode.OK); }
public async Task <IActionResult> Create([FromBody] UserPayload payload) { return(await RunDefaultAsync(async() => { await _userBusiness.Create(payload); return Ok(); })); }
public async Task <IActionResult> UpdateUser([FromBody] UserPayload payload) { var user = await SingleOrError(_usersRepo.FindOne(EntityId)); var result = await _usersRepo.Update(user, payload); return(Ok(Mapper.Map <UserData>(result))); }
public static void Main(string[] args) { UserClient client = new UserClient(app_key, master_secret); UserPayload user = new UserPayload("jintian"); client.getUserStat(user); Console.ReadLine(); }
public void deleteUserTest() { String username = this.username; UserPayload user = new UserPayload(username); ResponseWrapper content = client.deleteUser(user); Assert.AreEqual(content.responseCode, HttpStatusCode.Forbidden); }
public static void Main(string[] args) { Console.WriteLine("*****开始注册管理员******"); UserClient client = new UserClient(app_key, master_secret); UserPayload admin = new UserPayload("jmessage", "password"); client.registAdmin(admin); Console.ReadLine(); }
public static void Main(string[] args) { Console.WriteLine("*****开始修改用户信息******"); UserClient client = new UserClient(app_key, master_secret); UserPayload user = new UserPayload("jintian"); client.deleteUser(user); Console.ReadLine(); }
public static void Main(string[] args) { UserClient client = new UserClient(app_key, master_secret); //需要修改的用户的用户名 UserPayload user = new UserPayload("jintian"); //需要修改的字段 user.new_password = "******"; client.updateUserPassword(user); Console.ReadLine(); }
public void updateUserPasswordTest() { UserPayload user = new UserPayload("jintian"); //需要修改的字段 user.new_password = "******"; ResponseWrapper content = client.updateUserPassword(user); Assert.AreEqual(content.responseCode, HttpStatusCode.NoContent); }
public async Task <IActionResult> CreateUser([FromBody] UserPayload payload) { (var temporaryPassword, var user) = await _usersRepo.CreateNewUser(payload); var userData = Mapper.Map <CreatedUserData>(user); userData.TemporaryPassword = temporaryPassword; return(Ok(userData)); }
public void updateUserTest() { UserPayload user = new UserPayload("jintian"); //需要修改的字段 user.nickname = "nickname"; ResponseWrapper content = client.updateUser(user); Assert.AreEqual(content.responseCode, HttpStatusCode.NoContent); }
public void registAdminTest() { Random ran = new Random(); int RandKey = ran.Next(100, 99999999); String randString = RandKey.ToString(); UserPayload admin = new UserPayload("jmessage" + randString, "password"); ResponseWrapper content = client.registAdmin(admin); //repeat add user Assert.AreEqual(content.responseCode, HttpStatusCode.Created); }
public async Task <User> SignInUser(string email, string password) { UserPayload p = new UserPayload() { email = email, password = password, returnSecureToken = true }; string URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + AuthKey; var data = await RecieveData(URL, p); return(CreateSignInUser(data, password)); }
public static void Main(string[] args) { Console.WriteLine("*****开始注册用户******"); UserClient client = new UserClient(app_key, master_secret); UserPayload user = new UserPayload("jmessage123", "password"); List <UserPayload> users = new List <UserPayload> { user }; ResponseWrapper content = client.registUser(users); Console.WriteLine(content.responseContent); }
public void registUserTest() { String username = this.username; UserPayload user = new UserPayload(username, "password"); List <UserPayload> users = new List <UserPayload> { user }; ResponseWrapper content = client.registUser(users); //repeat add user Assert.AreEqual(content.responseCode, HttpStatusCode.Created); }
public async Task <(string, User)> CreateNewUser(UserPayload basePayload) { var payload = Mapper.Map <UserFields>(basePayload); string password = GenerateTemporaryPassword(16); payload.PasswordHash = _stringHasher.Hash(password); payload.IsPasswordTemporary = true; var result = await base.Create(payload); return(password, result); }
public async Task Create(UserPayload payload) { if (await _userRepository.HasUsername(payload.Username)) { throw new InvalidProgramException("Esse usuário já existe."); } var entity = payload.PayloadToEntity(payload); entity.Roles = "user"; await _userRepository.Create(entity); }
public UserPayload GetPayloadById(int id) { var payload = new UserPayload { Mail = "", Token = "", Username = "" }; var userModel = _dbContext.Users.FirstOrDefault(x => x.Id == id); if (userModel != null) { payload.Mail = userModel.Email; payload.Username = userModel.Username; payload.Id = userModel.Id; } return(payload); }
public async Task <JsonResult> Post(Guid projectId, [FromBody] UserPayload user) { Ensure.ArgumentNotNull(user, nameof(user)); var userId = Guid.NewGuid(); var tenant = this.Tenant; await ExecuteNewAsync(tenant, Streams.Users, userId, async() => { var aggregate = new UserAggregate(); aggregate.RegisterNew(user.UserName, user.Email); return(await Task.FromResult(aggregate)); }); return(new JsonResult(new { id = userId })); }
public ActionResult <User> Create([FromBody] UserPayload payload) { try { var userToAdd = new User { FirstName = payload.FirstName, LastName = payload.LastName, Email = payload.Email }; _db.Users.Add(userToAdd); _db.SaveChanges(); return(Ok(userToAdd)); } catch (Exception) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public IActionResult AddUser(UserPayload userPayload) { User user = _db.Users.FirstOrDefault(u => u.UserId == userPayload.userId); if (user == null) { user = new User { UserId = userPayload.userId, UserName = userPayload.userName }; _db.Users.Add(user); } else { user.UserId = userPayload.userId; user.UserName = userPayload.userName; } _db.SaveChanges(); return(Ok()); }
static async Task Main(string[] args) { ToDo todoService_response = await RestUtility.CallServiceAsync <ToDo>(todoService_Get, string.Empty, null, "GET", string.Empty, string.Empty) as ToDo; IList <ToDo> lst_TodoService_response = await RestUtility.CallServiceAsync <IList <ToDo> >(todosService_Get, string.Empty, null, "GET", string.Empty, string.Empty) as IList <ToDo>; Users users = await RestUtility.CallServiceAsync <Users>(usersService_Get, string.Empty, null, "GET", string.Empty, string.Empty) as Users; UserPayload userPayload = new UserPayload() { Name = "John Doe", Job = "Software Engineer" }; UserResponse userResponse = await RestUtility.CallServiceAsync <UserResponse>(userService_Post, string.Empty, userPayload, "POST", string.Empty, string.Empty) as UserResponse; Console.ReadKey(); }
public async Task <UserProfileResponse> EditProfileDescription(EditProfileDescriptionRequest request, UserPayload payload) { var ent = _context.UserProfiles.Include(x => x.UserProfileImage).Include(x => x.User).FirstOrDefault(x => x.Id == payload.Id); if (ent != null) { ent.Description = request.Description; await _context.SaveChangesAsync(); } return(_mapper.Map <UserProfileResponse>(ent)); }
public async Task <UserProfileResponse> EditProfileImage(EditProfileImageRequest request, UserPayload payload) { var uploaded = await _imageService.UploadImage(request.Data); var profile = await _context.UserProfiles.Include(x => x.UserProfileImage).Include(x => x.User).FirstOrDefaultAsync(x => x.Id == payload.Id); profile.UserProfileImage = uploaded; await _context.SaveChangesAsync(); return(_mapper.Map <UserProfileResponse>(profile)); }