Exemple #1
0
        public async Task <IActionResult> Join([FromBody] UserModels.Join.Request request)
        {
            // check format
            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            // check verify code
            ErrorCode emailVerifyResult = CheckEMailVerifyCode(request.EMail, request.VerifyCode, false);

            if (emailVerifyResult != ErrorCode.Success)
            {
                return(APIResponse(emailVerifyResult));
            }

            // insert database
            DBQuery_User_Insert query = new DBQuery_User_Insert();

            basicData            = query.IN.BasicData;
            basicData.UserId     = IDGenerator.NewUserId;
            basicData.EMail      = request.EMail;
            basicData.CreateTime = DateTime.UtcNow;
            basicData.Password   = PasswordUtility.HashPassword(request.Password);

            if (await DBThread.Instance.ReqQueryAsync(query) == false)
            {
                return(APIResponse(ErrorCode.DatabaseError));
            }

            // response
            var response = new UserModels.Join.Response();

            response.EMail      = request.EMail;
            response.CreateTime = basicData.CreateTime;

            return(Success(response));
        }
Exemple #2
0
        // 로그인 처리
        private async Task <ErrorCode> ProcessLoginAsync(string email, string password, int timeZoneOffsetFromUTC = 0)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(ErrorCode.AlreadyLoggedin);
            }

            if (email.IsValidEmailAddress() == false)
            {
                return(ErrorCode.InvalidEMail);
            }

            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(email) == false)
            {
                return(ErrorCode.InvalidEMail);
            }

            if (PasswordUtility.VerifyPassword(password, basicData.Password) == false)
            {
                return(ErrorCode.InvalidPassword);
            }

            var claims = new List <Claim>();

            claims.Add(new Claim(HenaClaimTypes.UserId, basicData.UserId.ToString()));
            claims.Add(new Claim(HenaClaimTypes.GivenName, basicData.GivenName));
            claims.Add(new Claim(HenaClaimTypes.Surname, basicData.SurName));
            claims.Add(new Claim(HenaClaimTypes.Email, basicData.EMail));
            claims.Add(new Claim(HenaClaimTypes.Language, basicData.Language));
            claims.Add(new Claim(HenaClaimTypes.TimeZoneId, basicData.TimeZoneId));
            claims.Add(new Claim(HenaClaimTypes.TimeZoneOffset, TimeSpan.FromMinutes(timeZoneOffsetFromUTC).ToString()));

            var userIdentity = new ClaimsIdentity(claims, "login");

            ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
            await HttpContext.SignInAsync(principal);

            Response.Cookies.Delete(HenaClaimTypes.UserId);
            Response.Cookies.Append(HenaClaimTypes.UserId, basicData.UserId.ToString());


            return(ErrorCode.Success);
        }
Exemple #3
0
        public async Task <IActionResult> JoinVerifyEMail([FromBody] UserModels.JoinVerifyEMail.Request request)
        {
            // check format
            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            var response = new UserModels.JoinVerifyEMail.Response();

            return(Success(response));
        }
Exemple #4
0
        public async Task <IActionResult> ResetPassword([FromBody] UserModels.ResetPassword.Request request)
        {
            // check account
            UserBasicData basicData = new UserBasicData();

            if (await basicData.FromDBByEmailAsync(request.EMail) == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            string newPassword = IDGenerator.NewVerifyCode;

            basicData.Password = PasswordUtility.HashPassword(newPassword);

            var query = new DBQuery_User_Update_Password();

            query.IN.UserId   = basicData.UserId;
            query.IN.Password = basicData.Password;

            if (await DBThread.Instance.ReqQueryAsync(query) == false)
            {
                return(APIResponse(ErrorCode.DatabaseError));
            }


            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. {basicData.EMail.Split('@')[0]}"));
            msg.AppendLine(string.Format($"Reseted your password."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"Your temp password : {newPassword}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Reseted your password.", msg.ToString(), false, request.EMail);

            var response = new UserModels.ResetPassword.Response();

            return(Success(response));
        }
Exemple #5
0
        public async Task <IActionResult> SendVerifyEMail([FromBody] UserModels.SendVerifyEMail.Request request)
        {
            // check account
            UserBasicData basicData = new UserBasicData();

            if (request.EMail.IsValidEmailAddress() == false)
            {
                return(APIResponse(ErrorCode.InvalidEMail));
            }

            if (await basicData.FromDBByEmailAsync(request.EMail))
            {
                return(APIResponse(ErrorCode.ExistEMail));
            }

            // generate verify data
            var verifyData = VerifyDataManager.Instance.NewVerifyData(TimeSpan.FromMinutes(3)
                                                                      , TimeSpan.FromHours(1), true, request);

            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. "));
            msg.AppendLine(string.Format($"Please enter your verification code below and complete verification."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"CODE : {verifyData.VerifyCode}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Signup verification code.", msg.ToString(), false, request.EMail);

            // response
            var response = new UserModels.SendVerifyEMail.Response();

            response.EMail    = request.EMail;
            response.SendTime = DateTime.UtcNow;

            return(Success(response));
        }