Esempio n. 1
0
        public ApiResponse EditEnrolnName([FromBody] UserReq model)
        {
            int    userId        = GetCurrentUserId();
            int    gainPoints    = 0;
            string gainPointsMsg = "";

            if (string.IsNullOrEmpty(model.EnrolnName))
            {
                return(new ApiResponse(Metas.Info_NULL));
            }
            if (model.EnrolnName.Length < 2 || model.EnrolnName.Length > 6)
            {
                return(new ApiResponse(Metas.EnrolnName_LengthError));
            }
            PublicUser thisUser = ncBase.CurrentEntities.PublicUser.Where(o => o.UserID == userId).FirstOrDefault();

            if (thisUser.IsNoNull())
            {
                thisUser.EnrolnName = model.EnrolnName;
                ncBase.CurrentEntities.SaveChanges();

                DoTask(userId, PointsEnum.First_EnrolnName, out gainPoints);
                gainPointsMsg = "完成“修改真实姓名”任务";
            }

            var result = new
            {
                GainPoints    = gainPoints,
                GainPointsMsg = gainPointsMsg
            };

            return(new ApiResponse(Metas.SUCCESS, result));
        }
Esempio n. 2
0
        public ApiResponse EditPortrait([FromBody] UserReq model)
        {
            int    userId        = GetCurrentUserId();
            int    gainPoints    = 0;
            string gainPointsMsg = "";

            if (string.IsNullOrEmpty(model.Portrait))
            {
                return(new ApiResponse(Metas.Portrait_NULL));
            }
            PublicUser thisUser = ncBase.CurrentEntities.PublicUser.Where(o => o.UserID == userId).FirstOrDefault();

            if (thisUser.IsNoNull())
            {
                thisUser.Portrait = model.Portrait;
                ncBase.CurrentEntities.SaveChanges();

                DoTask(userId, PointsEnum.First_UploadHead, out gainPoints);
                gainPointsMsg = "完成“有头有脸”任务";
            }

            var result = new
            {
                GainPoints    = gainPoints,
                GainPointsMsg = gainPointsMsg
            };

            return(new ApiResponse(Metas.SUCCESS, result));
        }
Esempio n. 3
0
        public ApiResponse EditPwd([FromBody] UserReq model)
        {
            if (string.IsNullOrEmpty(model.NewPwd) || model.NewPwd.Length < 6)
            {
                return(new ApiResponse(Metas.PwdLength_Wrong));
            }
            var    credential = Request.GetCredential();
            int    userId     = 0;
            string userName   = "";

            if (credential != null)
            {
                userId   = credential.UserID;
                userName = credential.Name;
            }
            UserBll         userBll   = new UserBll();
            PublicUserModel checkUser = userBll.PublicUserLogin(userName, model.OldPwd, 0);

            if (checkUser != null && checkUser.UserID > 0)
            {
                int row = userBll.UpdateUserPassword(checkUser.UserID, model.NewPwd);
                if (row > 0)
                {
                    return(new ApiResponse(Metas.SUCCESS));
                }
                else
                {
                    return(new ApiResponse(Metas.UNKNOWN_ERROR));
                }
            }
            else
            {
                return(new ApiResponse(Metas.PASSWORD_WRONG));
            }
        }
Esempio n. 4
0
        public static UserResp GetUser()
        {
            var req = new UserReq();

            req.Nickname = "用户692778";
            return(_client.GetUser(req));
        }
Esempio n. 5
0
        // Get single user
        public UserDTO Get(UserReq request)
        {
            UserDTO userDTO = null;

            try
            {
                if (String.IsNullOrEmpty(WindowsHelper.WindowsUserName))
                {
                    throw new ApplicationException("Windows Authentication is not enabled");
                }
                else
                {
                    UserAuth userAuth = Db.Select <UserAuth>(u => u.UserName == WindowsHelper.WindowsUserName).FirstOrDefault();
                    userDTO = new UserDTO
                    {
                        AppUser           = userAuth,
                        IsAdmin           = userAuth.Roles.Contains(HeadcountResource.Administrator_Role),
                        IsReadOnlyUser    = userAuth.Roles.Contains(HeadcountResource.Readonly_User_Role),
                        IsFacilitiesAdmin = userAuth.Roles.Contains(HeadcountResource.Facilities_Admin_Role),
                        IsSecurityTeam    = userAuth.Roles.Contains(HeadcountResource.Security_Team_Role),
                        IsSystemAdmin     = userAuth.Roles.Contains(HeadcountResource.System_Admin_Role),
                    };
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.InsertError("app Error " + WindowsHelper.WindowsUserName, ex);
            }
            return(userDTO);
        }
Esempio n. 6
0
        public HttpResponseMessage Suggest(UserReq req)
        {
            var tokenStr = req.Token;
            var userId   = Convert.ToInt32(req.userId);

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            var        content = req.suggestion;
            Suggestion sug     = new Suggestion();

            sug.userId  = userId;
            sug.content = content;
            sug.sTime   = DateTime.Now;
            SuggestionOper.Instance.Add(sug);
            return(ControllerHelper.Instance.JsonResult(200, "建议成功"));
        }
Esempio n. 7
0
        public HttpResponseMessage GetPayRecord(UserReq req)
        {
            var tokenStr = req.Token;
            var userId   = Convert.ToInt32(req.userId);

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }


            var pageIndex = Convert.ToInt32(req.pageIndex);

            var list = CacheHelper.GetByConditionPaging <UserPayView>("UserPayView", " userid=" + userId, pageIndex, size, " order by createTime desc");

            if (list.Count < 1)
            {
                return(ControllerHelper.Instance.JsonEmptyArr(200, "暂无记录"));
            }
            var listR = new List <PayRecordRes>();

            foreach (var item in list)
            {
                PayRecordRes pr = new PayRecordRes(item);
                listR.Add(pr);
            }
            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(listR), ""));
        }
Esempio n. 8
0
        public HttpResponseMessage SetPassword(UserReq req)
        {
            var tokenStr = req.Token;
            var userId   = Convert.ToInt32(req.userId);

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            var pwd = MD5Helper.Instance.StrToMD5(req.password);

            var userHere = new UserInfo();

            userHere.id      = userId;
            userHere.userPwd = pwd;
            try
            {
                UserInfoOper.Instance.Update(userHere);
                return(ControllerHelper.Instance.JsonResult(200, "设置成功"));
            }
            catch (Exception e)
            {
                return(ControllerHelper.Instance.JsonResult(200, "服务器错误"));
            }
        }
Esempio n. 9
0
        public HttpResponseMessage IsUserClicked(UserReq req)
        {
            var jo = new JObject();

            var count = ArticleInfoOper.Instance.GetArticleCount();

            if (count == 0)
            {
                jo.Add("isClicked", true);
                return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), ""));
            }

            if (req == null)
            {
                jo.Add("isClicked", false);
                return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), ""));
            }
            var userId = Convert.ToInt32(req.userId);

            if (userId == 0)
            {
                jo.Add("isClicked", false);
                return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), ""));
            }

            var flag = CacheHelper.IsUserArticleClick(userId);

            jo.Add("isClicked", flag);
            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), ""));
        }
Esempio n. 10
0
        //分割线,以上已写接口文档
        /*————————————————————————————————————————————————*/

        /// <summary>
        /// 留着,不知道需不需要
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public HttpResponseMessage SendMail(UserReq user)
        {
            var phone = user.phone;

            if (true)
            {
                string             verification = CacheHelper.SetRiderVerificationCode(phone);
                Enum_SendEmailCode SendEmail;
                SendEmail = Enum_SendEmailCode.UserRegistrationVerificationCode;
                SendSmsResponse Email = AliyunHelper.SendMail.SendMail.Instance.SendEmail(phone, verification, SendEmail);
                //string str = "";
                if (Email.Code.ToUpper() == "OK")
                {
                    return(ControllerHelper.Instance.JsonResult(200, "短信验证码发送成功"));
                }
                else
                {
                    return(ControllerHelper.Instance.JsonResult(500, Email.Message));
                }
            }
            else
            {
                //string str = JsonHelper.JsonMsg(false, "请过段时间重新发送");
                return(ControllerHelper.Instance.JsonResult(500, "请过段时间重新发送"));
            }
        }
Esempio n. 11
0
        public IActionResult Register([FromBody] UserReq userReq)
        {
            var user    = authService.Create(userReq);
            var userDto = mapper.Map <UserDto>(user);

            return(Ok(userDto));
        }
        public IActionResult CreateUser([FromBody] UserReq req)
        {
            var res = new SingleRsp();

            res = _svc.CreateUser(req);
            return(Ok(res));
        }
Esempio n. 13
0
        public override async Task <VoidRsp> CreateAsync(UserReq user)
        {
            VoidRsp rsp = new VoidRsp();

            rsp.Status  = 0;
            rsp.Message = "test";
            try
            {
                Logger.Debug("receive CreateAsync,data=" + Google.Protobuf.JsonFormatter.Default.Format(user));

                UserReq existing = await this._repo.FindByNameAsync(user.Account);

                if (existing != null)
                {
                    Logger.Debug("user already exists:{0}", user.Account);
                }
                Assert.IsNotNull(existing, "user already exists:" + user.Account);

                user.Password = CryptographyManager.Md5Encrypt(user.Account + "$" + user.Password);
                Logger.Debug("saving db");
                await this._repo.SaveUserAsync(user);

                Logger.Debug("saving db success");
            }
            catch (Exception ex) {
                rsp.Status  = -1;
                rsp.Message = ex.Message;
            }

            return(rsp);
        }
Esempio n. 14
0
        public HttpResponseMessage SetUserInfo(UserReq req)
        {
            var tokenStr = req.Token;
            var userId   = Convert.ToInt32(req.userId);

            Token token = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }

            var user = new UserInfo();

            user.id = userId;

            var headImgStr = req.headImg;
            var imgUrl     = "";

            if (!string.IsNullOrEmpty(headImgStr))
            {
                imgUrl = ControllerHelper.Instance.SaveHeadImg(headImgStr, apiHost, userId);
            }
            var name = req.name;

            if (!string.IsNullOrEmpty(name))
            {
                user.userName = name;
            }

            var birthday = req.birthday;

            if (!string.IsNullOrEmpty(birthday))
            {
                user.birthday = Convert.ToDateTime(birthday);
            }

            if (!string.IsNullOrEmpty(imgUrl))
            {
                user.userHead = imgUrl;
                var newImgName = imgUrl.Substring(imgUrl.LastIndexOf('/') + 1);
                ControllerHelper.Instance.DeleteOtherUserHeadImg(userId, newImgName);
            }

            UserInfoOper.Instance.Update(user);

            var view = UserInfoOper.Instance.GetViewByUserId(userId);

            if (view == null)
            {
                return(ControllerHelper.Instance.JsonResult(500, "用户不存在"));
            }
            UserInfoRes res = new UserInfoRes(view, apiHost, tokenStr);

            return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(res), "修改成功"));
        }
Esempio n. 15
0
        public ApiResponse EditMobile([FromBody] UserReq model)
        {
            if (string.IsNullOrEmpty(model.Phone))
            {
                return(new ApiResponse(Metas.Phone_NULL));
            }

            if (string.IsNullOrEmpty(model.Captcha) || userBll.CheckCaptcha(model.Phone, model.Captcha, model.Type) == 0)
            {
                return(new ApiResponse(Metas.Captcha_Wrong));
            }
            PublicUser telUser = ncBase.CurrentEntities.PublicUser.Where(u => u.Tel == model.Phone).FirstOrDefault();

            if (telUser.IsNoNull())
            {
                return(new ApiResponse(Metas.Phone_EXISTS));
            }
            int        userId    = GetCurrentUserId();
            PublicUser loginUser = ncBase.CurrentEntities.PublicUser.Where(u => u.UserID == userId).FirstOrDefault();

            loginUser.Tel = model.Phone;
            ncBase.CurrentEntities.SaveChanges();

            return(new ApiResponse(Metas.SUCCESS));
        }
Esempio n. 16
0
        public UserDto Authenticate(UserReq userReq)
        {
            var user    = GetValidUser(userReq);
            var userDto = mapper.Map <UserDto>(user);

            userDto.Token = GeneratetUserToken(user);
            return(userDto);
        }
Esempio n. 17
0
        public ApiResponse GenerateCaptcha([FromBody] UserReq model)
        {
            string captcha = StringUtility.GetValiCode();
            string content = String.Format("{0}(房产盒子验证码)", captcha);

            userBll.PostGenerateCaptcha(model.Phone, content, captcha, model.Type);
            return(new ApiResponse(Metas.SUCCESS));
        }
Esempio n. 18
0
        protected async Task <UserRes> UserRegisterAsync(UserReq request)
        {
            var response = await TestClient.PostAsJsonAsync("api/register", request);

            var result = await response.Content.ReadAsAsync <ResultExtended <UserRes> >();

            return(result.Succeeded ? result.Data : null);
        }
        public SingleResponse ValidateUser(UserReq req)
        {
            var result = new SingleResponse();
            var search = base.All.Where(value => value.PhoneNumber == req.Username &&
                                        value.Password == PasswordHasher.HashPassword(req.Password)).FirstOrDefault();

            result.Data = search;
            return(result);
        }
Esempio n. 20
0
        private UserModel GetValidUser(UserReq userReq)
        {
            var user = userService.FindByUsername(userReq.Username);

            if (!VerifyPasswordHash(userReq.Password, user.PasswordHash, user.PasswordSalt))
            {
                throw new ArgumentException($"Password for {user.Username} is incorrect!");
            }
            return(user);
        }
Esempio n. 21
0
        public IActionResult UpdateUser([FromBody] UserReq req)
        {
            SHA256 sha256 = SHA256Managed.Create(); //utf8 here as well

            byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(req.Password));
            req.Password = Convert.ToBase64String(bytes);
            var res = _svc.UpdateUser(req);

            return(Ok(res));
        }
Esempio n. 22
0
        /// <summary>
        /// 社交账号中 绑定QQ或微信
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public HttpResponseMessage BuildContact(UserReq req)
        {
            var mode   = req.BindMode;
            var userId = Convert.ToInt32(req.userId);
            var qq     = req.qq;
            var wechat = req.wechat;

            var   tokenStr = req.Token;
            Token token    = CacheHelper.GetUserToken(tokenStr);

            if (token == null)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token失效"));
            }
            if (token.Payload.UserID != userId)
            {
                return(ControllerHelper.Instance.JsonResult(400, "token错误"));
            }


            if (mode == "QQ")
            {
                var list = UserInfoOper.Instance.GetByQQ(qq);
                if (list.Count > 0)
                {
                    return(ControllerHelper.Instance.JsonResult(500, "该QQ已绑定其他账号"));
                }
                else
                {
                    //user.qq = qq;
                    var user = new UserInfo();
                    user.id = userId;
                    user.qq = qq;
                    UserInfoOper.Instance.Update(user);
                    return(ControllerHelper.Instance.JsonResult(200, "QQ账号绑定成功"));
                }
            }
            else
            {
                var list = UserInfoOper.Instance.GetByQQ(wechat);
                if (list.Count > 0)
                {
                    return(ControllerHelper.Instance.JsonResult(500, "该微信已绑定其他账号"));
                }
                else
                {
                    //user.wechat = wechat;
                    var user = new UserInfo();
                    user.id     = userId;
                    user.wechat = wechat;
                    UserInfoOper.Instance.Update(user);
                    return(ControllerHelper.Instance.JsonResult(200, "微信账号绑定成功"));
                }
            }
        }
Esempio n. 23
0
        public IActionResult ValidateUser([FromBody] UserReq req)
        {
            var result = _svc.ValidateUser(req);

            //Khi đã đăng nhập thành công thì sẽ tạo 1 session lưu tên người dùng
            if (result.Success)
            {
                HttpContext.Session.SetString("EmpLoginSession", req.Username);
            }
            return(Ok(result));
        }
Esempio n. 24
0
 public Response Update(int id, [FromBody] UserReq model)
 {
     try
     {
         return(null);
     }
     catch (Exception ex)
     {
         return(new Response(ex.ToString()));
     }
 }
Esempio n. 25
0
        public async Task <IActionResult> NewUserJsonAsync([FromBody] UserReq model)
        {
            var response = await _userService.NewUser(model);

            if (response == false)
            {
                return(BadRequest(new { msg = "Account already exists.", status = "failed" }));
            }

            return(Ok(new { msg = "Account successfully created! Please check your email.", status = "success" }));
        }
Esempio n. 26
0
        public IActionResult AuthenticateJson([FromBody] UserReq model)
        {
            var response = _userService.Authenticate(model);

            if (response == null)
            {
                return(BadRequest(new { msg = "Email or password is incorrect", status = "success" }));
            }

            return(Ok(new { msg = "You're logged in!", status = "success", jwt = response.Token }));
        }
Esempio n. 27
0
        public IActionResult AuthenticateJson([FromBody] UserReq model)
        {
            var response = _userService.Authenticate(model);

            if (response == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(response));
        }
Esempio n. 28
0
        public override async Task <AccountRsp> CreateAsync(UserReq user)
        {
            AccountRsp rsp = new AccountRsp();

            try
            {
                Logger.Debug("receive CreateAsync,data=" + Google.Protobuf.JsonFormatter.Default.Format(user));
                Account existing = await this._accountRep.FindByNameAsync(user.Account);

                Assert.IsNotNull(existing, "用户已经存在了");

                Logger.Debug("start call AuthService");
                //调用远端
                var authClient = ClientProxy.GetClient <AuthServiceClient>();
                var voidRsp    = await authClient.CreateAsync(user);

                if (voidRsp.Status != 0)
                {
                    rsp.Status  = voidRsp.Status;
                    rsp.Message = voidRsp.Message;
                    return(rsp);
                }
                Logger.Debug("end call AuthService");

                Saving saving = new Saving()
                {
                    Amount         = 0,
                    Currency       = Currency.Usd,
                    Interest       = 0,
                    Deposit        = false,
                    Capitalization = false,
                    Account        = user.Account
                };
                Account account = new Account();

                account.Name         = user.Account;
                account.CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                account.LastSeenTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                Logger.Debug("start save to db");
                await this._accountRep.SaveUserAsync(account);

                await this._accountRep.SaveAccountSavingAsync(saving);

                Logger.Info("new account has been created:{0} ", user.Account);
                rsp.Data = account;
            }
            catch (Exception ex)
            {
                rsp.Status  = -1;
                rsp.Message = ex.Message;
            }
            return(rsp);
        }
Esempio n. 29
0
 public HttpResponseMessage UploadUserClose(UserReq req)
 {
     if (req != null)
     {
         var userId = Convert.ToInt32(req.userId);
         var uo     = UserOpenInfoOper.Instance.GetLastByUserId(userId);
         uo.closeTime = DateTime.Now;
         UserOpenInfoOper.Instance.Update(uo);
         return(ControllerHelper.Instance.JsonResult(200, "已记录"));
     }
     return(ControllerHelper.Instance.JsonResult(200, "没登陆不记录"));
 }
Esempio n. 30
0
        public Task Send(UserReq req)
        {
            _logger.Info($"user name: {req.Name}");
            var addCommand = _bus.SendAsync(new AddUserCommand {
                UserName = req.Name
            });
            var addEvent = _bus.PublishAsync(new UserAdded {
                UserName = req.Name
            });

            Task.WaitAll(addCommand, addEvent);
            return(Task.CompletedTask);
        }